Skip to content

rich_click.decorators

Functions

NameDescription
argumentAdd a positional argument to the command.
commandCreate a command.
command_panelShow a group of subcommands in a panel of its own in the help output.
confirmation_optionAdd a --yes option. Without it, the command asks the user to confirm, and exits if they decline.
groupCreate a group of subcommands.
help_optionAdd a --help option that prints the help and exits.
optionAdd an option to the command.
option_panelShow a group of options in a panel of its own in the help output.
pass_contextMarks a callback as wanting to receive the current context object as first argument.
password_optionAdd a --password option that prompts for the password two times and hides the input.
rich_configSet the help configuration and the Rich console of one command or group.
version_optionAdd a --version option that prints the version and exits.

argumentfunction#

def argument(*param_decls: str, cls: type[click.Argument] | None = None, **attrs: Any) -> Callable[[FC], FC]

Add a positional argument to the command.

The same as click.argument, but the argument is a RichArgument unless you set cls.

Parameters

NameTypeDefaultDescription
*param_declsstr()Name of the argument.
clstype[click.Argument] | NoneNoneArgument class. Defaults to RichArgument.
**attrsAny{}Other arguments for the cls constructor, such as nargs and type. See click.Argument.

Returns

Callable[[FC], FC]
A decorator that adds the argument to a command.

commandfunction#

def command(name: str | None | _AnyCallable = None, cls: type[CmdType] | None = None, **attrs: Any) -> Command | Callable[[_AnyCallable], RichCommand | CmdType]

Create a command.

The same as click.command, but the command is a RichCommand unless you set cls.

command_panelfunction#

def command_panel(name: str, cls: type[RichPanel[Command, Any]] = RichCommandPanel, **attrs: Any) -> Callable[[FC], FC]

Show a group of subcommands in a panel of its own in the help output.

Parameters

NameTypeDefaultDescription
namestrrequiredTitle of the panel.
clstype[RichPanel[Command, Any]]RichCommandPanelPanel class. Defaults to RichCommandPanel.
**attrsAny{}Other arguments for the panel class, such as commands and help.

Returns

Callable[[FC], FC]
A decorator that adds the panel to a group.

confirmation_optionfunction#

def confirmation_option(*param_decls: str, **kwargs: Any) -> Callable[[FC], FC]

Add a --yes option. Without it, the command asks the user to confirm, and exits if they decline.

Parameters

NameTypeDefaultDescription
*param_declsstr()Option names. Defaults to --yes.
**kwargsAny{}Other arguments for option.

Returns

Callable[[FC], FC]
A decorator that adds the option to a command.

groupfunction#

def group(name: str | _AnyCallable | None = None, cls: type[G] | None = None, **attrs: Any) -> Group | Callable[[_AnyCallable], RichGroup | G]

Create a group of subcommands.

The same as click.group, but the group is a RichGroup unless you set cls.

help_optionfunction#

def help_option(*param_decls: str, **kwargs: Any) -> Callable[[FC], FC]

Add a --help option that prints the help and exits.

Parameters

NameTypeDefaultDescription
*param_declsstr()Option names. Defaults to --help.
**kwargsAny{}Other arguments for option.

Returns

Callable[[FC], FC]
A decorator that adds the option to a command.

optionfunction#

def option(*param_decls: str, cls: type[click.Option] | None = None, **attrs: Any) -> Callable[[FC], FC]

Add an option to the command.

The same as click.option, but the option is a RichOption unless you set cls.

Parameters

NameTypeDefaultDescription
*param_declsstr()Names of the option, such as "--count" and "-c".
clstype[click.Option] | NoneNoneOption class. Defaults to RichOption.
**attrsAny{}Other arguments for the cls constructor, such as default and help. See click.Option.

Returns

Callable[[FC], FC]
A decorator that adds the option to a command.

option_panelfunction#

def option_panel(name: str, cls: type[RichPanel[Parameter, Any]] = RichOptionPanel, **attrs: Any) -> Callable[[FC], FC]

Show a group of options in a panel of its own in the help output.

Parameters

NameTypeDefaultDescription
namestrrequiredTitle of the panel.
clstype[RichPanel[Parameter, Any]]RichOptionPanelPanel class. Defaults to RichOptionPanel.
**attrsAny{}Other arguments for the panel class, such as options and help.

Returns

Callable[[FC], FC]
A decorator that adds the panel to a command or group.

pass_contextfunction#

def pass_context(f: Callable[Concatenate[RichContext, PSpec], R]) -> Callable[PSpec, R]

Marks a callback as wanting to receive the current context object as first argument.

password_optionfunction#

def password_option(*param_decls: str, **kwargs: Any) -> Callable[[FC], FC]

Add a --password option that prompts for the password two times and hides the input.

Parameters

NameTypeDefaultDescription
*param_declsstr()Option names. Defaults to --password.
**kwargsAny{}Other arguments for option.

Returns

Callable[[FC], FC]
A decorator that adds the option to a command.

rich_configfunction#

def rich_config(help_config: dict[str, Any] | RichHelpConfiguration | None = None, *, console: Console | None = None) -> Callable[[FC], FC]

Set the help configuration and the Rich console of one command or group.

Parameters

NameTypeDefaultDescription
help_configdict[str, Any] | RichHelpConfiguration | NoneNoneHow to format help and errors, as a RichHelpConfiguration or a dict of its fields.
consoleConsole | NoneNoneRich console to print help and errors with. The context makes it available as ctx.console.

Returns

Callable[[FC], FC]
A decorator that applies the settings to a command or group.

version_optionfunction#

def version_option(version: str | None = None, *param_decls: str, package_name: str | None = None, prog_name: str | None = None, message: str | None = None, **kwargs: Any) -> Callable[[FC], FC]

Add a --version option that prints the version and exits.

Parameters

NameTypeDefaultDescription
versionstr | NoneNoneVersion to print. If not set, Click reads it from the metadata of the installed package_name. If Click cannot find the version, --version raises a RuntimeError.
*param_declsstr()Option names. Defaults to --version.
package_namestr | NoneNoneInstalled package to read the version from. If not set, it is the top-level package of the module that calls version_option.
prog_namestr | NoneNoneName of the CLI in the message. If not set, Click uses the name of the command.
messagestr | NoneNoneMessage to print. It can use %(prog)s, %(package)s and %(version)s. Defaults to "%(prog)s, version %(version)s".
**kwargsAny{}Other arguments for option.

Returns

Callable[[FC], FC]
A decorator that adds the option to a command.