Format click help output nicely with rich
npx @tessl/cli install tessl/pypi-rich-click@1.8.0Rich-Click is a Python library that provides attractive help output from Click, formatted with Rich, with minimal customization required. It serves as a drop-in replacement for Click while enhancing command-line interfaces with rich text formatting, colors, and visual enhancements.
pip install rich-clickimport rich_click as clickOr use specific imports:
from rich_click import command, group, option, argument
from rich_click import RichCommand, RichGroup, RichContext
from rich_click import __version____version__: str = "1.8.9"import rich_click as click
@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for _ in range(count):
click.echo(f"Hello, {name}!")
if __name__ == '__main__':
hello()Rich-Click extends Click's architecture with Rich formatting capabilities:
Essential decorators for creating rich-formatted Click commands and groups with enhanced help output and styling capabilities.
def command(name=None, cls=None, **attrs):
"""Create a rich-formatted command."""
def group(name=None, cls=None, **attrs):
"""Create a rich-formatted command group."""
def pass_context(f):
"""Pass RichContext to the decorated function."""
def rich_config(help_config=None, *, console=None):
"""Configure Rich settings for commands."""Enhanced Click classes with rich formatting capabilities including command classes, context management, and configuration systems.
class RichCommand(click.Command):
"""Enhanced Click command with rich formatting."""
class RichGroup(click.Group):
"""Enhanced Click group with rich formatting."""
class RichContext(click.Context):
"""Enhanced Click context with Rich capabilities."""
class RichHelpConfiguration:
"""Comprehensive configuration for Rich help formatting."""Comprehensive configuration system for customizing Rich-Click appearance, behavior, and styling with extensive options for colors, panels, tables, and text formatting.
class RichHelpConfiguration:
# Style configuration
style_option: str = "bold cyan"
style_argument: str = "bold cyan"
style_command: str = "bold cyan"
# ... many more styling options
# Behavior configuration
show_arguments: bool = False
show_metavars_column: bool = True
text_markup: str = "ansi"
# ... many more behavior optionsComplete Click API re-exported for drop-in compatibility including all core classes, decorators, exceptions, types, and utility functions.
# Core classes
class Command: ...
class Group: ...
class Context: ...
class Option: ...
class Argument: ...
# Decorators
def option(*param_decls, **attrs): ...
def argument(*param_decls, **attrs): ...
# Exception classes
class ClickException(Exception): ...
class UsageError(ClickException): ...
class BadParameter(UsageError): ...Utility functions for patching existing Click applications and various helper functions for working with Rich-Click components.
def patch(rich_config=None):
"""Patch Click internals to use rich-click types."""
def truthy(o):
"""Check if string or other obj is truthy."""
class CommandGroupDict(TypedDict):
"""Specification for command groups."""
class OptionGroupDict(TypedDict):
"""Specification for option groups."""Rich-Click CLI tool for enhancing external Click applications with rich formatting without modifying their source code.
def main(ctx, script_and_args, output, errors_in_output_format,
suppress_warnings, rich_config, show_help):
"""Rich-click CLI command entry point."""