Skip to content

Sub-commands

If j exports too many commands, it might make sense to group them into subcommands. This is done by defining Typer applications in jeeves.py.

jeeves.py
import typer

lint = typer.Typer(no_args_is_help=True)
test = typer.Typer(no_args_is_help=True)


@lint.command(name='mypy')
def _mypy():
    """Run mypy."""


@lint.command(name='flake8')
def _flake8():
    """Run flake8."""
    print(_flake8.__doc__)


@test.command(name='unit')
def _unit():
    """Run unit tests."""


@test.command(name='integration')
def _integration():
    """Run integration tests."""

Top level documentation

j
 Usage: j [OPTIONS] COMMAND [ARGS]...                                           

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --log-level                 [debug|info|error]  Logging level.               │
│                                                 [default: LogLevel.ERROR]    │
│ --install-completion                            Install completion for the   │
│                                                 current shell.               │
│ --show-completion                               Show completion for the      │
│                                                 current shell, to copy it or │
│                                                 customize the installation.  │
│ --help                                          Show this message and exit.  │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ lint                                                                         │
│ test                                                                         │
╰──────────────────────────────────────────────────────────────────────────────╯

Hidden commands

Note that we have to use underscore here, otherwise def mypy and other functions will be bound to the top-level j command. See def _hidden() for details. See Jeeves package to see how to avoid that.

Sub-command level documentation

j lint
 Usage: j lint [OPTIONS] COMMAND [ARGS]...                                      

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ flake8                       Run flake8.                                     │
│ mypy                         Run mypy.                                       │
╰──────────────────────────────────────────────────────────────────────────────╯

Nested command

j lint flake8
Run flake8.