Skip to content

rich_click.rich_async_command

Rich-formatted command classes for asyncclick.

asyncclick is a fork of click with async command methods (main, invoke, make_context and parse_args). The rich-click mixins (RichCommandMixin, RichGroupMixin and RichContextMixin) have no click base class, so these classes combine them with the asyncclick classes.

Most code does not import these classes. Call rich_click.patch.patch(module=asyncclick) instead. It puts these classes into the asyncclick namespace, so @asyncclick.command CLIs get rich-click help.

Classes

NameDescription
RichAsyncCommandRichly formatted asyncclick Command.
RichAsyncCommandCollectionRichly formatted asyncclick CommandCollection.
RichAsyncContextAn asyncclick Context that formats help and errors with Rich.
RichAsyncGroupRichly formatted asyncclick Group.

RichAsyncCommandclass#

class RichAsyncCommand(RichCommandMixin, asyncclick.Command)

Bases: RichCommandMixin, asyncclick.Command

Richly formatted asyncclick Command.

Combines the help and error formatting of RichCommandMixin with the asynchronous asyncclick.Command (async main and invoke).

context_classattributeclass attributeinstance attribute#

context_class: type[RichAsyncContext] = RichAsyncContext

invokemethodasync#

async def invoke(ctx: asyncclick.Context) -> Any

mainmethodasync#

async def main(args: Sequence[str] | None = None, prog_name: str | None = None, complete_var: str | None = None, standalone_mode: bool = True, **extra: Any) -> Any

make_contextmethodasync#

async def make_context(*args: Any, **kwargs: Any) -> Any

to_info_dictmethodasync#

async def to_info_dict(ctx: asyncclick.Context) -> dict[str, Any]
Inherited from rich_click.rich_command.RichCommandMixin

aliasesattributeinstance attribute#

aliases: Iterable[str] = aliases or []

panelattributeinstance attribute#

panel: str | list[str] | None = panel

panelsattributeinstance attribute#

panels: list[RichPanel[Any, Any]] = panels or []

consolepropertyDeprecated#

console: Console | None

Rich console of this command. Set it with the rich_config decorator.

help_configpropertyDeprecated#

help_config: RichHelpConfiguration | None

Help configuration of this command. Set it with the rich_config decorator.

add_panelmethod#

def add_panel(panel: RichPanel[Any, Any]) -> None

Add a RichPanel to the RichCommand.

format_epilogmethod#

def format_epilog(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_helpmethod#

def format_help(ctx: click.Context, formatter: click.HelpFormatter) -> None

Write the help: the usage, the help text, the options and the epilog.

Each part has its own format_* method, so a subclass can override one part.

format_help_textmethod#

def format_help_text(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_optionsmethod#

def format_options(ctx: click.Context, formatter: click.HelpFormatter) -> None

get_help_optionmethod#

def get_help_option(ctx: click.Context) -> click.Option | None

Return the help option, or None if add_help_option is false. Every call returns the same object.

get_rich_table_rowmethod#

def get_rich_table_row(ctx: RichContext, formatter: RichHelpFormatter, panel: RichCommandPanel | None = None) -> RichPanelRow

Create a row for the rich table corresponding with this parameter.

RichAsyncCommandCollectionclass#

class RichAsyncCommandCollection(asyncclick.CommandCollection, RichAsyncGroup)

Bases: asyncclick.CommandCollection, RichAsyncGroup

Richly formatted asyncclick CommandCollection.

Inherited from rich_click.rich_async_command.RichAsyncGroup

command_classattributeclass attributeinstance attribute#

command_class: type[RichAsyncCommand] | None = RichAsyncCommand

context_classattributeclass attributeinstance attribute#

context_class: type[RichAsyncContext] = RichAsyncContext

group_classattributeclass attributeinstance attribute#

group_class: Any | None = type
Inherited from rich_click.rich_command.RichGroupMixin

add_commandmethod#

def add_command(cmd: click.Command, name: str | None = None, aliases: Iterable[str] | None = None, panel: str | list[str] | None = None) -> None

Add a command to this group.

Parameters

NameTypeDefaultDescription
cmdclick.CommandrequiredThe command to add.
namestr | NoneNoneName of the command in this group. Defaults to the name of the command.
aliasesIterable[str] | NoneNoneOther names that run the command, in addition to the aliases of the command.
panelstr | list[str] | NoneNonePanel or panels to show the command in, by panel title.

add_command_to_panelmethod#

def add_command_to_panel(command: click.Command, panel_name: str | Iterable[str]) -> None

commandmethod#

def command(*args: Any, **kwargs: Any) -> Any

Create a command and add it to this group.

Takes the same arguments as the command decorator, and works with or without parentheses. The class of the command is command_class, unless you set cls.

format_commandsmethod#

def format_commands(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_helpmethod#

def format_help(ctx: RichContext, formatter: RichHelpFormatter) -> None

get_commandmethod#

def get_command(ctx: click.Context, cmd_name: str) -> click.Command | None

groupmethod#

def group(*args: Any, **kwargs: Any) -> Any

Create a subgroup and add it to this group.

Takes the same arguments as the group decorator, and works with or without parentheses. The subgroup has the same class as this group, unless you set group_class or cls.

Inherited from rich_click.rich_async_command.RichAsyncCommand

invokemethodasync#

async def invoke(ctx: asyncclick.Context) -> Any

mainmethodasync#

async def main(args: Sequence[str] | None = None, prog_name: str | None = None, complete_var: str | None = None, standalone_mode: bool = True, **extra: Any) -> Any

make_contextmethodasync#

async def make_context(*args: Any, **kwargs: Any) -> Any

to_info_dictmethodasync#

async def to_info_dict(ctx: asyncclick.Context) -> dict[str, Any]
Inherited from rich_click.rich_command.RichCommandMixin

aliasesattributeinstance attribute#

aliases: Iterable[str] = aliases or []

panelattributeinstance attribute#

panel: str | list[str] | None = panel

panelsattributeinstance attribute#

panels: list[RichPanel[Any, Any]] = panels or []

consolepropertyDeprecated#

console: Console | None

Rich console of this command. Set it with the rich_config decorator.

help_configpropertyDeprecated#

help_config: RichHelpConfiguration | None

Help configuration of this command. Set it with the rich_config decorator.

add_panelmethod#

def add_panel(panel: RichPanel[Any, Any]) -> None

Add a RichPanel to the RichCommand.

format_epilogmethod#

def format_epilog(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_help_textmethod#

def format_help_text(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_optionsmethod#

def format_options(ctx: click.Context, formatter: click.HelpFormatter) -> None

get_help_optionmethod#

def get_help_option(ctx: click.Context) -> click.Option | None

Return the help option, or None if add_help_option is false. Every call returns the same object.

get_rich_table_rowmethod#

def get_rich_table_row(ctx: RichContext, formatter: RichHelpFormatter, panel: RichCommandPanel | None = None) -> RichPanelRow

Create a row for the rich table corresponding with this parameter.

RichAsyncContextclass#

class RichAsyncContext(RichContextMixin, asyncclick.Context)

Bases: RichContextMixin, asyncclick.Context

An asyncclick Context that formats help and errors with Rich.

Inherited from rich_click.rich_context.RichContextMixin

consoleattributeclass attributeinstance attribute#

console: Console | None = None

errors_in_output_formatattributeclass attributeinstance attribute#

errors_in_output_format: bool = False

export_console_asattributeclass attributeinstance attribute#

export_console_as: Literal['html', 'svg', 'text'] | None = None

formatter_classattributeclass attributeinstance attribute#

formatter_class: type[RichHelpFormatter] = RichHelpFormatter

help_configattributeinstance attribute#

help_config = parent.help_config

help_to_stderrattributeclass attributeinstance attribute#

help_to_stderr: bool = False

make_formattermethod#

def make_formatter(error_mode: bool = False) -> RichHelpFormatter

Create the Rich Help Formatter.

RichAsyncGroupclass#

class RichAsyncGroup(RichGroupMixin, RichAsyncCommand, asyncclick.Group)

Bases: RichGroupMixin, RichAsyncCommand, asyncclick.Group

Richly formatted asyncclick Group.

Subcommands and subgroups created from this group inherit the async rich classes via command_class and group_class, so the whole command tree renders richly.

command_classattributeclass attributeinstance attribute#

command_class: type[RichAsyncCommand] | None = RichAsyncCommand

context_classattributeclass attributeinstance attribute#

context_class: type[RichAsyncContext] = RichAsyncContext

group_classattributeclass attributeinstance attribute#

group_class: Any | None = type
Inherited from rich_click.rich_command.RichGroupMixin

add_commandmethod#

def add_command(cmd: click.Command, name: str | None = None, aliases: Iterable[str] | None = None, panel: str | list[str] | None = None) -> None

Add a command to this group.

Parameters

NameTypeDefaultDescription
cmdclick.CommandrequiredThe command to add.
namestr | NoneNoneName of the command in this group. Defaults to the name of the command.
aliasesIterable[str] | NoneNoneOther names that run the command, in addition to the aliases of the command.
panelstr | list[str] | NoneNonePanel or panels to show the command in, by panel title.

add_command_to_panelmethod#

def add_command_to_panel(command: click.Command, panel_name: str | Iterable[str]) -> None

commandmethod#

def command(*args: Any, **kwargs: Any) -> Any

Create a command and add it to this group.

Takes the same arguments as the command decorator, and works with or without parentheses. The class of the command is command_class, unless you set cls.

format_commandsmethod#

def format_commands(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_helpmethod#

def format_help(ctx: RichContext, formatter: RichHelpFormatter) -> None

get_commandmethod#

def get_command(ctx: click.Context, cmd_name: str) -> click.Command | None

groupmethod#

def group(*args: Any, **kwargs: Any) -> Any

Create a subgroup and add it to this group.

Takes the same arguments as the group decorator, and works with or without parentheses. The subgroup has the same class as this group, unless you set group_class or cls.

Inherited from rich_click.rich_async_command.RichAsyncCommand

invokemethodasync#

async def invoke(ctx: asyncclick.Context) -> Any

mainmethodasync#

async def main(args: Sequence[str] | None = None, prog_name: str | None = None, complete_var: str | None = None, standalone_mode: bool = True, **extra: Any) -> Any

make_contextmethodasync#

async def make_context(*args: Any, **kwargs: Any) -> Any

to_info_dictmethodasync#

async def to_info_dict(ctx: asyncclick.Context) -> dict[str, Any]
Inherited from rich_click.rich_command.RichCommandMixin

aliasesattributeinstance attribute#

aliases: Iterable[str] = aliases or []

panelattributeinstance attribute#

panel: str | list[str] | None = panel

panelsattributeinstance attribute#

panels: list[RichPanel[Any, Any]] = panels or []

consolepropertyDeprecated#

console: Console | None

Rich console of this command. Set it with the rich_config decorator.

help_configpropertyDeprecated#

help_config: RichHelpConfiguration | None

Help configuration of this command. Set it with the rich_config decorator.

add_panelmethod#

def add_panel(panel: RichPanel[Any, Any]) -> None

Add a RichPanel to the RichCommand.

format_epilogmethod#

def format_epilog(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_help_textmethod#

def format_help_text(ctx: click.Context, formatter: click.HelpFormatter) -> None

format_optionsmethod#

def format_options(ctx: click.Context, formatter: click.HelpFormatter) -> None

get_help_optionmethod#

def get_help_option(ctx: click.Context) -> click.Option | None

Return the help option, or None if add_help_option is false. Every call returns the same object.

get_rich_table_rowmethod#

def get_rich_table_row(ctx: RichContext, formatter: RichHelpFormatter, panel: RichCommandPanel | None = None) -> RichPanelRow

Create a row for the rich table corresponding with this parameter.