API Reference
Protocols
Section titled “Protocols”CLIApplicationProtocol
Section titled “CLIApplicationProtocol”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.
property runner() -> CLIRunnerProtocol
The underlying command runner.
Start the application, boot providers, and prepare for dispatch.
Tear down resources and exit cleanly.
CLIRunnerProtocol
Section titled “CLIRunnerProtocol”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.
Parse argv (or sys.argv) and dispatch to the matching command.
| Parameter | Type | Description |
|---|---|---|
| `argv` | list[str] | None | Argument vector to parse. Defaults to ``sys.argv[1:]``. |
| Type | Description |
|---|---|
| int | Exit code (0 for success, non-zero for failure). |
def register_command(command: CommandProtocol) -> None
Register a command with this runner.
| Parameter | Type | Description |
|---|---|---|
| `command` | CommandProtocol | A CommandProtocol implementation to register. |
CommandProtocol
Section titled “CommandProtocol”Protocol for CLI command implementations.
Execute the command.
| Parameter | Type | Description |
|---|---|---|
| `args` | list[str] | Positional arguments |
| `options` | dict[str, Any] | Parsed options dictionary |
| Type | Description |
|---|---|
| int | Exit code (0 for success) |
Command name.
Command description.
Get help text for the command.
| Type | Description |
|---|---|
| str | Help text |
Classes
Section titled “Classes”CLIConfig
Section titled “CLIConfig”
CLIContext
Section titled “CLIContext”Shared context object passed through Typer to all commands.
Holds the OutputManager, loaded config, and global flag state.
def __init__( *, json_mode: bool = False, quiet: bool = False, debug: bool = False, no_color: bool = False, config_path: Path | None = None ) -> None
Lazily load and return config data asynchronously.
Lazily load and return the config data for synchronous call sites.
Load config, raising ConfigNotFoundError if absent.
CLIModule
Section titled “CLIModule”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): passdef configure( cls, config: Any | None = None ) -> DynamicModule
Create a CLIModule with explicit configuration.
| Parameter | Type | Description |
|---|---|---|
| `config` | Any | None | CLIConfig or ``None`` for framework defaults. |
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule descriptor. |
def stub(cls) -> DynamicModule
Return a no-op CLIModule for testing.
Registers the CLI provider with default configuration. No commands are registered by default.
| Type | Description |
|---|---|
| DynamicModule | A DynamicModule with default CLI configuration. |
OutputManager
Section titled “OutputManager”Unified output manager for all CLI commands.
def __init__( *, json_mode: bool = False, quiet: bool = False, debug: bool = False, no_color: bool = False ) -> None
Print a success message.
Print an error message. Shown even in quiet mode.
Print a warning message.
Print an informational message.
Print tabular data.
Print key-value pairs.
def cli_error(err: CliError) -> None
Render a structured CLIError with causes and suggestions.
Print a debug message (only shown in debug mode).
Pass-through to Rich console.print for one-off needs.
Functions
Section titled “Functions”find_config
Section titled “find_config”
Locate the lexigram config file.
| Parameter | Type | Description |
|---|---|---|
| `explicit_path` | Path | None | If given, use this path directly. |
| `start_dir` | Path | None | Directory to start searching from (default: CWD). |
| Type | Description |
|---|---|
| Path | Resolved Path to the config file. |
| Exception | Description |
|---|---|
| ConfigNotFoundError | If no config file is found. |
handle_errors
Section titled “handle_errors”
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
Section titled “load_config_yaml”
Load and parse a YAML config file from synchronous call sites.
Exceptions
Section titled “Exceptions”CliError
Section titled “CliError”Base exception for lexigram-cli operations.
def __init__( message: str | None = None, causes: list[str] | None = None, suggestions: list[str] | None = None, **kwargs: Any ) -> None
Initialize CLI error.
| Parameter | Type | Description |
|---|---|---|
| `message` | str | None | Human-readable error message. |
| `causes` | list[str] | None | List of potential causes for the error. |
| `suggestions` | list[str] | None | List of suggestions to resolve the error. **kwargs: Additional keyword arguments passed to parent. |
ConfigNotFoundError
Section titled “ConfigNotFoundError”Raised when application.yaml configuration file is not found.
ProviderNotInstalledError
Section titled “ProviderNotInstalledError”Raised when a required provider package is not installed.
Initialize provider not installed error.
| Parameter | Type | Description |
|---|---|---|
| `provider` | str | Name of the missing provider. |