Skip to main content

Customizing Command Metadata

You can customize the metadata of your CLI commands and groups to provide better documentation, control visibility, and organize the help output. This is primarily achieved by configuring attributes on the TyperCommand and TyperGroup classes through the @app.command() and @app.callback() decorators.

Customizing Help Text and Epilogs

The most common way to provide help text is through docstrings, but you can also use the help, short_help, and epilog parameters for more control.

import typer

app = typer.Typer()

@app.command(
help="Create a new user in the system. This is the long help text.",
short_help="Create a user.",
epilog="For more information, visit https://example.com/docs"
)
def create(username: str):
print(f"Creating user: {username}")

if __name__ == "__main__":
app()
  • help: The full description shown when running command --help. If omitted, the function's docstring is used.
  • short_help: A brief summary shown in the command list of a group.
  • epilog: Text displayed at the very bottom of the help output.

Controlling Visibility: Hidden and Deprecated

You can hide commands from the help menu or mark them as deprecated to warn users without removing functionality.

import typer

app = typer.Typer()

@app.command(hidden=True)
def secret_command():
"""This command exists but won't show up in --help."""
print("Running secret operations...")

@app.command(deprecated=True)
def old_delete(username: str):
"""
Delete a user.
This is deprecated and will stop being supported soon.
"""
print(f"Deleting user: {username}")

if __name__ == "__main__":
app()
  • hidden=True: The command remains executable but is omitted from the help listing.
  • deprecated=True: The command is shown in help with a "Deprecated" warning label.

Enhancing Help with Rich Formatting

If you have the rich library installed, you can use Markdown or Rich markup tags in your help strings by setting rich_markup_mode.

import typer

# Set rich_markup_mode to "rich" or "markdown"
app = typer.Typer(rich_markup_mode="rich")

@app.command(epilog="Made with :heart: in [blue]Venus[/blue]")
def create(username: str):
"""
[green]Create[/green] a new user. :sparkles:

You can use **standard** Rich tags here.
"""
print(f"Creating user: {username}")

if __name__ == "__main__":
app()

Organizing Commands into Panels

When a CLI has many commands, you can group them into logical sections using the rich_help_panel attribute of TyperCommand.

import typer

app = typer.Typer(rich_markup_mode="rich")

@app.command(rich_help_panel="Utils and Configs")
def config(configuration: str):
"""[blue]Configure[/blue] the system. :gear:"""
print(f"Configuring: {configuration}")

@app.command(rich_help_panel="Utils and Configs")
def sync():
"""[blue]Synchronize[/blue] the system. :recycle:"""
print("Syncing...")

@app.command(rich_help_panel="Help and Others")
def report():
"""[yellow]Report[/yellow] an issue. :exclamation:"""
print("Reporting issue...")

if __name__ == "__main__":
app()

Command Ordering in Groups

Unlike standard Click groups which sort commands alphabetically, TyperGroup maintains the original order of command registration. This allows you to control the sequence in which commands appear in the help menu simply by the order they are defined in your code.

Troubleshooting

  • Markup not rendering: Ensure rich_markup_mode is explicitly set to "rich" or "markdown" on the Typer app or the specific command. By default, it may be None or use standard Click formatting.
  • Rich features missing: Features like panels and colored markup require the rich package. If rich is not installed, TyperCommand and TyperGroup will fall back to standard Click help formatting.