Skip to content

User guide

typer-swissknife has a handful of pieces. Each page covers one of them.

Piece What it does Page
command(app, aliases=...) a command callable by several names, listed once Commands and aliases
add_typer(app, sub_app, aliases=...) a command group callable by several names Command groups
add_typer(app, SomeClass) with @command() methods a class whose marked methods are a group's commands Classes as command groups
ascii_name=, get_ascii_help_text a pyfiglet banner at the top of a help page ASCII-art banners
def fn(**kwargs) with command undeclared --key value options passed to **kwargs Undeclared options

The mental model

flowchart TD
    F["your function"] -->|"command(app, aliases=('ls',))"| H["hidden commands<br/>list, ls"]
    F -->|"command(app, aliases=('ls',))"| V["visible entry<br/>list (ls)"]
    S["sub-app"] -->|"add_typer(app, sub, aliases=('a',))"| G["hidden groups admin, a<br/>+ visible entry admin (a)"]

Both helpers are thin wrappers over app.command() and app.add_typer():

  1. Without aliases, ascii_name or **kwargs, they register exactly what Typer would.
  2. With aliases, the name and every alias are registered as hidden commands (or groups), plus one visible entry such as list (ls) for the help output.
  3. With ascii_name, the help text is replaced by a banner followed by the original help.
  4. command returns your function unchanged, so you can still call it directly.

Every other parameter (help, epilog, hidden, rich_help_panel, cls...) is passed to Typer as is.

Single-command apps

Typer runs an app that has a single registered command and no groups as that command, without a subcommand name. The examples in this guide register at least two commands so the command names stay in the command line.