Using the decorator `@app.callback`, you can declare the CLI parameters for the main CLI application. Read more in the [Typer docs for Callbacks](https://typer.tiangolo.com/tutorial/commands/callback/). ## Example ```python import typer ap
(
self,
*,
cls: Annotated[
type[TyperGroup] | None,
Doc(
"""
The class of this app. 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 `TyperGroup`.
"""
),
] = Default(None),
invoke_without_command: Annotated[
bool,
Doc(
"""
By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
"""
),
] = Default(False),
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.
"""
),
] = Default(False),
subcommand_metavar: Annotated[
str | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
from Click and supported for compatibility.
---
How to represent the subcommand argument in help.
"""
),
] = Default(None),
chain: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
from Click and supported for compatibility.
---
Allow passing more than one subcommand argument.
"""
),
] = Default(False),
result_callback: Annotated[
Callable[..., Any] | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited
from Click and supported for compatibility.
---
A function to call after the group's and subcommand's callbacks.
"""
),
] = Default(None),
# Command
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).
"""
),
] = Default(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.
"""
),
] = Default(None),
epilog: Annotated[
str | None,
Doc(
"""
Text that will be printed right after the help text.
"""
),
] = Default(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.
"""
),
] = Default(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.
"""
),
] = Default(True),
hidden: Annotated[
bool,
Doc(
"""
Hide this command from help outputs. `False` by default.
"""
),
] = Default(False),
deprecated: Annotated[
bool,
Doc(
"""
Mark this command as deprecated in the help text. `False` by default.
"""
),
] = 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),
)
| 547 | self.registered_callback: TyperInfo | None = None |
| 548 | |
| 549 | def callback( |
| 550 | self, |
| 551 | *, |
| 552 | cls: Annotated[ |
| 553 | type[TyperGroup] | None, |
| 554 | Doc( |
| 555 | """ |
| 556 | The class of this app. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`. |
| 557 | Otherwise, should be a subtype of `TyperGroup`. |
| 558 | """ |
| 559 | ), |
| 560 | ] = Default(None), |
| 561 | invoke_without_command: Annotated[ |
| 562 | bool, |
| 563 | Doc( |
| 564 | """ |
| 565 | By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided. |
| 566 | """ |
| 567 | ), |
| 568 | ] = Default(False), |
| 569 | no_args_is_help: Annotated[ |
| 570 | bool, |
| 571 | Doc( |
| 572 | """ |
| 573 | If this is set to `True`, running a command without any arguments will automatically show the help page. |
| 574 | """ |
| 575 | ), |
| 576 | ] = Default(False), |
| 577 | subcommand_metavar: Annotated[ |
| 578 | str | None, |
| 579 | Doc( |
| 580 | """ |
| 581 | **Note**: you probably shouldn't use this parameter, it is inherited |
| 582 | from Click and supported for compatibility. |
| 583 | |
| 584 | --- |
| 585 | |
| 586 | How to represent the subcommand argument in help. |
| 587 | """ |
| 588 | ), |
| 589 | ] = Default(None), |
| 590 | chain: Annotated[ |
| 591 | bool, |
| 592 | Doc( |
| 593 | """ |
| 594 | **Note**: you probably shouldn't use this parameter, it is inherited |
| 595 | from Click and supported for compatibility. |
| 596 | |
| 597 | --- |
| 598 | |
| 599 | Allow passing more than one subcommand argument. |
| 600 | """ |
| 601 | ), |
| 602 | ] = Default(False), |
| 603 | result_callback: Annotated[ |
| 604 | Callable[..., Any] | None, |
| 605 | Doc( |
| 606 | """ |