Skip to content

patera.cli

CLI controllers. See the CLI guide.

Cli methods

CLIController

CLIController(app: AppT)

Bases: Injectable, Generic[AppT]

Base class for CLI controllers.

Methods decorated with @command become commands, run as patera cli <controller>:<command> [args...]. Arguments are read from the method signature and converted to its annotated types.

app property

app: AppT

Returns the Patera app instance.

commands

commands() -> list[CLICommand]

Lists this controller's commands as controller:command names with their arguments and help text, sorted by name.

usage

usage(method: Callable) -> str

Describes a command's arguments: <name:type> for required ones and [name:type=default] for optional ones.

run_command

run_command(method: Callable, *args, **kwargs)

Runs a CLI command. On failure the error is printed to stderr and the process exits with status code 1, so scripts/CI can detect failures.

convert_value

convert_value(value: str, annotation: type) -> Any

Convert a CLI string value to the annotated type.

prepare_cli_args

prepare_cli_args(method, raw_args: list[str]) -> list[Any]

Convert raw CLI args to properly typed args based on method annotations. Missing optional arguments take their defaults. A missing required argument, or more arguments than the method accepts, raises ValueError.

CLICommand

Bases: NamedTuple

One application command, as listed by patera cli.

command

command(command_name: str, help: str = '')