Skip to content
GitHub

API Reference

Protocol for a top-level CLI application.

A CLIApplication owns a CLIRunnerProtocol and manages the full lifecycle of a CLI process: configuration loading, provider boot, command dispatch, and shutdown.

runner
property runner() -> CLIRunnerProtocol

The underlying command runner.

boot
async def boot() -> None

Start the application, boot providers, and prepare for dispatch.

shutdown
async def shutdown() -> None

Tear down resources and exit cleanly.


Protocol for objects that can run CLI commands.

A CLIRunner discovers registered CommandProtocol implementations and dispatches invocations based on the command name. Implementations may wrap Click, Typer, argparse, or any other CLI framework.

run
def run(argv: list[str] | None = None) -> int

Parse argv (or sys.argv) and dispatch to the matching command.

Parameters
ParameterTypeDescription
`argv`list[str] | NoneArgument vector to parse. Defaults to ``sys.argv[1:]``.
Returns
TypeDescription
intExit code (0 for success, non-zero for failure).
register_command
def register_command(command: CommandProtocol) -> None

Register a command with this runner.

Parameters
ParameterTypeDescription
`command`CommandProtocolA CommandProtocol implementation to register.

Protocol for CLI command implementations.
execute
def execute(
    args: list[str],
    options: dict[str, Any]
) -> int

Execute the command.

Parameters
ParameterTypeDescription
`args`list[str]Positional arguments
`options`dict[str, Any]Parsed options dictionary
Returns
TypeDescription
intExit code (0 for success)
name
property name() -> str

Command name.

description
property description() -> str

Command description.

get_help
def get_help() -> str

Get help text for the command.

Returns
TypeDescription
strHelp text


Shared context object passed through Typer to all commands.

Holds the OutputManager, loaded config, and global flag state.

__init__
def __init__(
    *,
    json_mode: bool = False,
    quiet: bool = False,
    debug: bool = False,
    no_color: bool = False,
    config_path: Path | None = None
) -> None
load_config_data
async def load_config_data() -> dict[str, Any]

Lazily load and return config data asynchronously.

config_data
property config_data() -> dict[str, Any]

Lazily load and return the config data for synchronous call sites.

require_config
def require_config() -> dict[str, Any]

Load config, raising ConfigNotFoundError if absent.


CLI command registration and configuration.

Call configure to configure the CLI provider.

Usage

from lexigram.cli.config import CLIConfig
@module(
imports=[CLIModule.configure(CLIConfig(...))]
)
class AppModule(Module):
pass
from lexigram.cli.config import CLIConfig
@module(
imports=[CLIModule.configure(CLIConfig(...))]
)
class AppModule(Module):
pass
configure
def configure(
    cls,
    config: Any | None = None
) -> DynamicModule

Create a CLIModule with explicit configuration.

Parameters
ParameterTypeDescription
`config`Any | NoneCLIConfig or ``None`` for framework defaults.
Returns
TypeDescription
DynamicModuleA DynamicModule descriptor.
stub
def stub(
    cls,
    config: Any = None
) -> DynamicModule

Return a no-op CLIModule for testing.

Registers the CLI provider with default configuration. No commands are registered by default.

Returns
TypeDescription
DynamicModuleA DynamicModule with default CLI configuration.

Unified output manager for all CLI commands.
__init__
def __init__(
    *,
    json_mode: bool = False,
    quiet: bool = False,
    debug: bool = False,
    no_color: bool = False
) -> None
success
def success(
    message: str,
    data: dict[str, Any] | None = None
) -> None

Print a success message.

error
def error(
    message: str,
    hint: str | None = None
) -> None

Print an error message. Shown even in quiet mode.

warning
def warning(message: str) -> None

Print a warning message.

info
def info(message: str) -> None

Print an informational message.

table
def table(
    headers: list[str],
    rows: list[list[str]]
) -> None

Print tabular data.

key_value
def key_value(data: dict[str, Any]) -> None

Print key-value pairs.

cli_error
def cli_error(err: CliError) -> None

Render a structured CLIError with causes and suggestions.

debug_msg
def debug_msg(message: str) -> None

Print a debug message (only shown in debug mode).

print
def print(
    *args: Any,
    **kwargs: Any
) -> None

Pass-through to Rich console.print for one-off needs.


find_config
def find_config(
    *,
    explicit_path: Path | None = None,
    start_dir: Path | None = None
) -> Path
Locate the lexigram config file.
Parameters
ParameterTypeDescription
`explicit_path`Path | NoneIf given, use this path directly.
`start_dir`Path | NoneDirectory to start searching from (default: CWD).
Returns
TypeDescription
PathResolved Path to the config file.
Raises
ExceptionDescription
ConfigNotFoundErrorIf no config file is found.

handle_errors
def handle_errors(func: F) -> F
Decorator that catches exceptions and renders friendly CLI errors.

Wraps a Typer command function to catch CliError (renders with causes/suggestions) and unexpected exceptions (renders with traceback hint).


load_config_yaml
def load_config_yaml(path: Path) -> dict[str, Any]
Load and parse a YAML config file from synchronous call sites.

Base exception for lexigram-cli operations.
__init__
def __init__(
    message: str | None = None,
    causes: list[str] | None = None,
    suggestions: list[str] | None = None,
    **kwargs: Any
) -> None

Initialize CLI error.

Parameters
ParameterTypeDescription
`message`str | NoneHuman-readable error message.
`causes`list[str] | NoneList of potential causes for the error.
`suggestions`list[str] | NoneList of suggestions to resolve the error. **kwargs: Additional keyword arguments passed to parent.

Raised when application.yaml configuration file is not found.
__init__
def __init__() -> None

Initialize config not found error.


Raised when a required provider package is not installed.
__init__
def __init__(provider: str) -> None

Initialize provider not installed error.

Parameters
ParameterTypeDescription
`provider`strName of the missing provider.