API¶
command¶
command(
app: typer.Typer | None = None,
*,
name: str | None = None,
aliases: Iterable[str] | None = None,
ascii_name: str | None = None,
ascii_font: str = DEFAULT_ASCII_FONT,
cls: type[TyperCommand] | None = None,
context_settings: dict[Any, Any] | None = None,
help: str | None = None,
epilog: str | None = None,
short_help: str | None = None,
options_metavar: str | None = Default(None),
add_help_option: bool = True,
no_args_is_help: bool = False,
hidden: bool = False,
deprecated: bool = False,
rich_help_panel: str | None = Default(None),
) -> Callable[[F], F]
Register the decorated function as a command of app, like @app.command(). The
decorator returns the function unchanged.
| Parameter | Description |
|---|---|
app |
the Typer app to add the command to; leave it out to mark a method of a class passed to add_typer |
name |
the command name; defaults to the function name in kebab case |
aliases |
other names the command can be called by; a single string is one alias; duplicates and the name itself are dropped |
ascii_name |
text drawn as a banner at the top of the help page |
ascii_font |
the pyfiglet font for ascii_name |
help |
the help text; defaults to the docstring |
short_help |
the text in the commands list; with ascii_name, defaults to the first paragraph of the help |
hidden |
hide the command, including its aliases, from the help |
cls, context_settings, epilog, options_metavar, add_help_option, no_args_is_help, deprecated, rich_help_panel |
same as in typer.Typer.command |
When the function takes **kwargs, undeclared --key value options are collected into
it, converted with the **kwargs annotation. Your context_settings are merged over the
allow_extra_args / ignore_unknown_options settings this needs.
Raises ValueError if an alias or ascii_name is empty, and pyfiglet.FontNotFound
for an unknown ascii_font.
Guide: Commands and aliases, Undeclared options.
add_typer¶
add_typer(
app: typer.Typer,
sub_app: typer.Typer | object,
*,
name: str | None = Default(None),
aliases: Iterable[str] | None = None,
ascii_name: str | None = None,
ascii_font: str = DEFAULT_ASCII_FONT,
cls: type[TyperGroup] | None = Default(None),
invoke_without_command: bool = Default(False),
no_args_is_help: bool = Default(False),
subcommand_metavar: str | None = Default(None),
chain: bool = Default(False),
result_callback: Callable[..., Any] | None = Default(None),
context_settings: dict[Any, Any] | None = Default(None),
callback: Callable[..., Any] | None = Default(None),
help: str | None = Default(None),
epilog: str | None = Default(None),
short_help: str | None = Default(None),
options_metavar: str | None = Default(None),
add_help_option: bool = Default(True),
hidden: bool = Default(False),
deprecated: bool = Default(False),
rich_help_panel: str | None = Default(None),
) -> typer.Typer
Add sub_app to app as a command group, like app.add_typer(). Parameters that are
not passed keep the values set on sub_app (in typer.Typer(...) or its callback).
| Parameter | Description |
|---|---|
app |
the parent Typer app |
sub_app |
the Typer app added as a group, or a class or instance whose @command() methods become the commands |
name |
the group name; defaults to the name set on sub_app |
aliases |
other names the group can be called by; a single string is one alias |
ascii_name |
text drawn as a banner at the top of the group's help page |
ascii_font |
the pyfiglet font for ascii_name |
help |
the help text; defaults to the help set on sub_app |
short_help |
the text in the commands list; with ascii_name, defaults to the first paragraph of the help |
hidden |
hide the group, including its aliases, from the help |
cls, invoke_without_command, no_args_is_help, subcommand_metavar, chain, result_callback, context_settings, callback, epilog, options_metavar, add_help_option, deprecated, rich_help_panel |
same as in typer.Typer.add_typer |
Raises ValueError if aliases are given but neither name nor sub_app has a name,
if an alias is empty, or if ascii_name is empty.
Returns the added sub-app (the built one for a class), so more groups can be added to it.
Guide: Command groups, Classes as command groups.
get_ascii_help_text¶
get_ascii_help_text(
title: str,
*,
body: str | None = None,
font: str = DEFAULT_ASCII_FONT,
markup_mode: MarkupMode = DEFAULT_MARKUP_MODE,
) -> str
Build help text that starts with title drawn as a banner, followed by body as its own
paragraph. The banner is wrapped so Typer does not rewrap it in markup_mode:
markup_mode |
Result |
|---|---|
"markdown" |
a fenced text code block |
"rich" |
\b followed by the art, with Rich markup escaped |
None |
a \b line, then the art |
Raises like render_ascii_art.
Guide: ASCII-art banners.
render_ascii_art¶
Render text with pyfiglet. Trailing whitespace is removed from every line, and blank
lines from the start and end.
Raises ValueError if text is empty or whitespace only, and pyfiglet.FontNotFound
if font is unknown.
DEFAULT_ASCII_FONT¶
The pyfiglet font used when no font is given.