CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rich-click

Format click help output nicely with rich

Pending
Overview
Eval results
Files

click-api.mddocs/

Click API Re-exports

Complete Click API re-exported for drop-in compatibility. Rich-Click re-exports the entire Click API unchanged, enabling it to serve as a direct replacement for Click while adding rich formatting capabilities.

Capabilities

Core Classes

Essential Click classes for building command-line interfaces, re-exported without modification.

class Command:
    """Base class for Click commands."""

class Group:
    """Base class for Click command groups."""

class CommandCollection:
    """Collection of multiple command sources."""

class Context:
    """Click context object for passing state."""

class Parameter:
    """Base class for command parameters."""

class Option:
    """Command option parameter."""

class Argument:
    """Command argument parameter."""

Decorators

Click decorators for building command-line interfaces, providing the foundation for CLI creation.

def option(*param_decls, **attrs):
    """
    Decorator for adding options to commands.
    
    Parameters:
    - *param_decls: Parameter declarations (e.g., '-v', '--verbose')
    - **attrs: Option attributes (type, help, default, etc.)
    
    Returns:
    Callable: Decorator function
    """

def argument(*param_decls, **attrs):
    """
    Decorator for adding arguments to commands.
    
    Parameters:
    - *param_decls: Parameter declarations  
    - **attrs: Argument attributes (type, help, etc.)
    
    Returns:
    Callable: Decorator function
    """

def confirmation_option(*param_decls, **attrs):
    """
    Decorator for adding confirmation options.
    
    Parameters:
    - *param_decls: Parameter declarations
    - **attrs: Option attributes
    
    Returns:
    Callable: Decorator function
    """

def help_option(*param_decls, **attrs):
    """
    Decorator for adding help options.
    
    Parameters:
    - *param_decls: Parameter declarations
    - **attrs: Option attributes
    
    Returns:
    Callable: Decorator function
    """

def password_option(*param_decls, **attrs):
    """
    Decorator for adding password options.
    
    Parameters:
    - *param_decls: Parameter declarations
    - **attrs: Option attributes
    
    Returns:
    Callable: Decorator function
    """

def version_option(*param_decls, **attrs):
    """
    Decorator for adding version options.
    
    Parameters:
    - *param_decls: Parameter declarations
    - **attrs: Option attributes
    
    Returns:
    Callable: Decorator function
    """

def make_pass_decorator(object_type):
    """
    Create a decorator that passes an object of the given type.
    
    Parameters:
    - object_type: Type of object to pass
    
    Returns:
    Callable: Pass decorator function
    """

def pass_obj(f):
    """
    Decorator that passes the context object.
    
    Parameters:
    - f (Callable): Function to decorate
    
    Returns:
    Callable: Decorated function
    """

Exception Classes

Click exception hierarchy for error handling in command-line applications.

class ClickException(Exception):
    """
    Base exception for all Click-related errors.
    
    Attributes:
    - message (str): Error message
    - exit_code (int): Process exit code
    """

class UsageError(ClickException):
    """
    Exception raised for usage errors.
    
    Raised when command usage is incorrect, such as missing
    required parameters or invalid option combinations.
    """

class BadParameter(UsageError):
    """
    Exception raised for bad parameter values.
    
    Raised when a parameter value is invalid or cannot be
    converted to the expected type.
    """

class BadArgumentUsage(BadParameter):
    """Exception raised for bad argument usage."""

class BadOptionUsage(BadParameter):
    """Exception raised for bad option usage."""

class MissingParameter(BadParameter):
    """Exception raised when required parameter is missing."""

class NoSuchOption(UsageError):
    """Exception raised when an unknown option is used."""

class FileError(ClickException):
    """Exception raised for file-related errors."""

class Abort(RuntimeError):
    """Exception raised to abort command execution."""

Type System

Click's parameter type system for validating and converting command-line arguments.

# Built-in type constants
BOOL: ParamType
"""Boolean parameter type."""

INT: ParamType  
"""Integer parameter type."""

FLOAT: ParamType
"""Float parameter type."""

STRING: ParamType
"""String parameter type."""

UNPROCESSED: ParamType
"""Unprocessed parameter type."""

UUID: ParamType
"""UUID parameter type."""

# Type classes
class ParamType:
    """Base class for parameter types."""
    
    def convert(self, value, param, ctx):
        """Convert parameter value."""
    
    def fail(self, message, param, ctx):
        """Fail with error message."""

class Choice(ParamType):
    """
    Parameter type for choosing from a list of values.
    
    Parameters:
    - choices (Sequence[str]): Available choices
    - case_sensitive (bool): Whether choices are case sensitive
    """

class IntRange(ParamType):
    """
    Parameter type for integers within a range.
    
    Parameters:
    - min (int, optional): Minimum value
    - max (int, optional): Maximum value
    - clamp (bool): Whether to clamp values to range
    """

class FloatRange(ParamType):
    """
    Parameter type for floats within a range.
    
    Parameters:
    - min (float, optional): Minimum value  
    - max (float, optional): Maximum value
    - clamp (bool): Whether to clamp values to range
    """

class DateTime(ParamType):
    """
    Parameter type for datetime values.
    
    Parameters:
    - formats (List[str]): Accepted datetime formats
    """

class File(ParamType):
    """
    Parameter type for file objects.
    
    Parameters:
    - mode (str): File mode ('r', 'w', 'rb', etc.)
    - encoding (str, optional): File encoding
    - errors (str): Error handling strategy
    - lazy (bool): Whether to open file lazily
    - atomic (bool): Whether to use atomic writes
    """

class Path(ParamType):
    """
    Parameter type for filesystem paths.
    
    Parameters:
    - exists (bool): Whether path must exist
    - file_okay (bool): Whether files are allowed
    - dir_okay (bool): Whether directories are allowed
    - writable (bool): Whether path must be writable
    - readable (bool): Whether path must be readable
    - resolve_path (bool): Whether to resolve relative paths
    - allow_dash (bool): Whether to allow '-' for stdin/stdout
    - path_type (type): Path type to return
    """

class Tuple(ParamType):
    """
    Parameter type for tuples of values.
    
    Parameters:
    - types (Sequence[ParamType]): Types for tuple elements
    """

Terminal UI Functions

Click's terminal user interface utilities for interactive command-line applications.

def echo(message=None, file=None, nl=True, err=False, color=None):
    """
    Print message to terminal.
    
    Parameters:
    - message: Message to print
    - file: File to write to
    - nl (bool): Whether to add newline
    - err (bool): Whether to write to stderr
    - color: Color setting
    """

def secho(message=None, file=None, nl=True, err=False, color=None, **styles):
    """
    Print styled message to terminal.
    
    Parameters:
    - message: Message to print
    - file: File to write to  
    - nl (bool): Whether to add newline
    - err (bool): Whether to write to stderr
    - color: Color setting
    - **styles: Style attributes (fg, bg, bold, etc.)
    """

def style(text, fg=None, bg=None, bold=None, dim=None, underline=None, 
          overline=None, italic=None, blink=None, reverse=None, 
          strikethrough=None, reset=True):
    """
    Style text with ANSI codes.
    
    Parameters:
    - text (str): Text to style
    - fg: Foreground color
    - bg: Background color  
    - bold (bool): Bold text
    - dim (bool): Dim text
    - underline (bool): Underlined text
    - italic (bool): Italic text
    - blink (bool): Blinking text
    - reverse (bool): Reverse colors
    - strikethrough (bool): Strikethrough text
    - reset (bool): Reset styles after text
    
    Returns:
    str: Styled text
    """

def unstyle(text):
    """
    Remove ANSI styling from text.
    
    Parameters:
    - text (str): Styled text
    
    Returns:  
    str: Unstyled text
    """

def clear():
    """Clear the terminal screen."""

def confirm(text, default=False, abort=False, prompt_suffix=': ', 
            show_default=True, err=False):
    """
    Show confirmation prompt.
    
    Parameters:
    - text (str): Prompt text
    - default (bool): Default value
    - abort (bool): Whether to abort on negative response
    - prompt_suffix (str): Suffix for prompt
    - show_default (bool): Whether to show default value
    - err (bool): Whether to write to stderr
    
    Returns:
    bool: User response
    """

def prompt(text, default=None, hide_input=False, confirmation_prompt=False,
           type=None, value_proc=None, prompt_suffix=': ', show_default=True,
           err=False, show_choices=True):
    """
    Show input prompt.
    
    Parameters:
    - text (str): Prompt text
    - default: Default value
    - hide_input (bool): Whether to hide input (password)
    - confirmation_prompt (bool): Whether to ask for confirmation
    - type: Parameter type for validation
    - value_proc: Value processing function
    - prompt_suffix (str): Suffix for prompt
    - show_default (bool): Whether to show default
    - err (bool): Whether to write to stderr
    - show_choices (bool): Whether to show choices
    
    Returns:
    Any: User input value
    """

def pause(info='Press any key to continue...', err=False):
    """
    Pause execution until key press.
    
    Parameters:
    - info (str): Info message to display
    - err (bool): Whether to write to stderr
    """

def getchar(echo=False):
    """
    Get single character from terminal.
    
    Parameters:  
    - echo (bool): Whether to echo character
    
    Returns:
    str: Character pressed
    """

def edit(text=None, editor=None, env=None, require_save=True,
         extension='.txt', filename=None):
    """
    Launch text editor.
    
    Parameters:
    - text (str): Initial text content
    - editor (str): Editor command to use
    - env (dict): Environment variables
    - require_save (bool): Whether save is required
    - extension (str): File extension for temp file
    - filename (str): Specific filename to use
    
    Returns:
    str: Edited text content
    """

def launch(url, wait=False, locate=False):
    """
    Launch URL or file in default application.
    
    Parameters:
    - url (str): URL or file path to launch
    - wait (bool): Whether to wait for application
    - locate (bool): Whether to locate file instead of opening
    
    Returns:
    int: Return code
    """

def echo_via_pager(text_or_generator, color=None):
    """
    Display text via system pager.
    
    Parameters:
    - text_or_generator: Text or generator yielding text
    - color: Color setting
    """

def progressbar(iterable=None, length=None, label=None, show_eta=True,
                show_percent=None, show_pos=False, item_show_func=None,
                fill_char='#', empty_char='-', bar_template='%(label)s  [%(bar)s]  %(info)s',
                info_sep='  ', width=36, file=None, color=None):
    """
    Display progress bar.
    
    Parameters:
    - iterable: Iterable to track progress
    - length (int): Total length if iterable has no len()
    - label (str): Label to display
    - show_eta (bool): Whether to show ETA
    - show_percent (bool): Whether to show percentage
    - show_pos (bool): Whether to show position
    - item_show_func: Function to format current item
    - fill_char (str): Character for filled portion
    - empty_char (str): Character for empty portion
    - bar_template (str): Template for bar format
    - info_sep (str): Separator for info section
    - width (int): Width of progress bar
    - file: File to write to
    - color: Color setting
    
    Returns:
    ProgressBar: Progress bar context manager
    """

Utility Functions

Click utility functions for common command-line tasks.

def get_current_context(silent=False):
    """
    Get the current Click context.
    
    Parameters:
    - silent (bool): Whether to fail silently if no context
    
    Returns:
    Context: Current context object
    
    Raises:
    RuntimeError: If no context available and not silent
    """

def format_filename(filename, shorten=False):
    """
    Format filename for display.
    
    Parameters:
    - filename (str): Filename to format
    - shorten (bool): Whether to shorten long paths
    
    Returns:
    str: Formatted filename
    """

def get_app_dir(app_name, roaming=True, force_posix=False):
    """
    Get application directory for storing data.
    
    Parameters:
    - app_name (str): Application name
    - roaming (bool): Whether to use roaming directory
    - force_posix (bool): Whether to force POSIX behavior
    
    Returns:
    str: Application directory path
    """

def get_binary_stream(name):
    """
    Get binary stream (stdin/stdout/stderr).
    
    Parameters:
    - name (str): Stream name ('stdin', 'stdout', 'stderr')
    
    Returns:
    BinaryIO: Binary stream
    """

def get_text_stream(name, encoding=None, errors='strict'):
    """
    Get text stream (stdin/stdout/stderr).
    
    Parameters:
    - name (str): Stream name ('stdin', 'stdout', 'stderr')
    - encoding (str): Text encoding
    - errors (str): Error handling
    
    Returns:
    TextIO: Text stream
    """

def open_file(filename, mode='r', encoding=None, errors='strict', lazy=False, atomic=False):
    """
    Open file with Click's file handling.
    
    Parameters:
    - filename (str): File to open
    - mode (str): File mode
    - encoding (str): Text encoding  
    - errors (str): Error handling
    - lazy (bool): Whether to open lazily
    - atomic (bool): Whether to use atomic writes
    
    Returns:
    IO: File object
    """

Help Formatting

Click's help formatting system.

class HelpFormatter:
    """
    Help formatter for Click commands.
    
    Formats help text with proper indentation and wrapping.
    """
    
    def write_usage(self, prog, args=None, prefix=None):
        """Write usage line."""
    
    def write_heading(self, heading):
        """Write section heading."""
    
    def write_paragraph(self):
        """Write paragraph break."""
    
    def write_text(self, text):
        """Write formatted text."""
    
    def write_dl(self, rows):
        """Write definition list."""

def wrap_text(text, width=78, initial_indent='', subsequent_indent='',
              preserve_paragraphs=False):
    """
    Wrap text to specified width.
    
    Parameters:
    - text (str): Text to wrap
    - width (int): Maximum line width
    - initial_indent (str): Indent for first line
    - subsequent_indent (str): Indent for continuation lines
    - preserve_paragraphs (bool): Whether to preserve paragraph breaks
    
    Returns:
    str: Wrapped text
    """

Install with Tessl CLI

npx tessl i tessl/pypi-rich-click

docs

classes.md

cli.md

click-api.md

configuration.md

decorators.md

index.md

utilities.md

tile.json