Using the decorator `@app.command`, you can define a subcommand of the previously defined Typer app. Read more in the [Typer docs for Commands](https://typer.tiangolo.com/tutorial/commands/). ## Example ```python import typer app = typer.T
(
self,
name: Annotated[
str | None,
Doc(
"""
The name of this command.
"""
),
] = None,
*,
cls: Annotated[
type[TyperCommand] | None,
Doc(
"""
The class of this command. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
Otherwise, should be a subtype of `TyperCommand`.
"""
),
] = None,
context_settings: Annotated[
dict[Any, Any] | None,
Doc(
"""
Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
"""
),
] = None,
help: Annotated[
str | None,
Doc(
"""
Help text for the command.
See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
and which one takes priority.
"""
),
] = None,
epilog: Annotated[
str | None,
Doc(
"""
Text that will be printed right after the help text.
"""
),
] = None,
short_help: Annotated[
str | None,
Doc(
"""
A shortened version of the help text that can be used e.g. in the help table listing subcommands.
When not defined, the normal `help` text will be used instead.
"""
),
] = None,
options_metavar: Annotated[
str | None,
Doc(
"""
In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
"""
),
] = Default(None),
add_help_option: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
from Click and supported for compatibility.
---
By default each command registers a `--help` option. This can be disabled by this parameter.
"""
),
] = True,
no_args_is_help: Annotated[
bool,
Doc(
"""
If this is set to `True`, running a command without any arguments will automatically show the help page.
"""
),
] = False,
hidden: Annotated[
bool,
Doc(
"""
Hide this command from help outputs. `False` by default.
"""
),
] = False,
deprecated: Annotated[
bool,
Doc(
"""
Mark this command as deprecated in the help outputs. `False` by default.
"""
),
] = False,
# Rich settings
rich_help_panel: Annotated[
str | None,
Doc(
"""
Set the panel name of the command when the help is printed with Rich.
"""
),
] = Default(None),
)
| 751 | return decorator |
| 752 | |
| 753 | def command( |
| 754 | self, |
| 755 | name: Annotated[ |
| 756 | str | None, |
| 757 | Doc( |
| 758 | class="st">""" |
| 759 | The name of this command. |
| 760 | class="st">""" |
| 761 | ), |
| 762 | ] = None, |
| 763 | *, |
| 764 | cls: Annotated[ |
| 765 | type[TyperCommand] | None, |
| 766 | Doc( |
| 767 | class="st">""" |
| 768 | The class of this command. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`. |
| 769 | Otherwise, should be a subtype of `TyperCommand`. |
| 770 | class="st">""" |
| 771 | ), |
| 772 | ] = None, |
| 773 | context_settings: Annotated[ |
| 774 | dict[Any, Any] | None, |
| 775 | Doc( |
| 776 | class="st">""" |
| 777 | Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/). |
| 778 | Available configurations can be found in the docs for Click&class="cm">#x27;s `Context` [here](https://click.palletsprojects.com/en/stable/api/#context). |
| 779 | class="st">""" |
| 780 | ), |
| 781 | ] = None, |
| 782 | help: Annotated[ |
| 783 | str | None, |
| 784 | Doc( |
| 785 | class="st">""" |
| 786 | Help text for the command. |
| 787 | See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command&class="cm">#x27;s help, |
| 788 | and which one takes priority. |
| 789 | class="st">""" |
| 790 | ), |
| 791 | ] = None, |
| 792 | epilog: Annotated[ |
| 793 | str | None, |
| 794 | Doc( |
| 795 | class="st">""" |
| 796 | Text that will be printed right after the help text. |
| 797 | class="st">""" |
| 798 | ), |
| 799 | ] = None, |
| 800 | short_help: Annotated[ |
| 801 | str | None, |
| 802 | Doc( |
| 803 | class="st">""" |
| 804 | A shortened version of the help text that can be used e.g. in the help table listing subcommands. |
| 805 | When not defined, the normal `help` text will be used instead. |
| 806 | class="st">""" |
| 807 | ), |
| 808 | ] = None, |
| 809 | options_metavar: Annotated[ |
| 810 | str | None, |