CLI instance defined in src/runegraft/cli.py. Use it to register commands, options, and root behavior; then hand off execution to CLI.run().
Constructing a CLI
name: controls how usage is rendered and becomes the default shell prompt (forge>).description: printed at the top ofhelpoutput.
ui.console, a Rich console configured with pretty tracebacks (see formatting.make_ui).
Registering commands
- Route strings are parsed by
parse_routeand enforce positional types; an error is raised at startup if a reserved shell command name is reused. - The first line of the docstring becomes the summary column in
help. - All function annotations are available during parsing, so you can combine route tokens and type hints (e.g., type hints drive option coercion).
@app.root to specify what runs when python -m runegraft is invoked with no arguments. Returning app.shell() matches the demo behavior, but you could launch a default command or print a welcome message.
Options and flags
Options are inferred from function parameters that are not present in the route:dry_runautomatically becomes--dry-runand, because it is typed asbool, behaves like a flag (--dry-runsets the value toTrue).- Non-bool parameters expect a value:
--retries 3. - Defaults come from the function signature; use
runegraft.cli.optionto override the long/short flag names or add help text.
Custom converters
Route tokens (<name:type>) map to converters defined in types.BUILTIN_TYPES. Register your own via CLI.type:
CLIError with a nice message both in the shell and non-interactive mode.
Execution helpers
CLI.run(argv: Optional[List[str]]): dispatch arguments (orsys.argv[1:]by default). Automatically handles--helpand empty input.CLI.invoke(tokens: List[str]): run one command when you already parsed the leading command name.CLI.shell(): construct and run the interactive loop fromshell.py.CLI.print_help(): render the Rich table shown in the shell.
CLIError for user-facing issues; let them bubble up so Rich can colorize the message. Only catch them for custom error handling or to translate into exit codes.