Base
π€ AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.cli.base
¶
Abstract CLI adapter protocol.
Defines the interface for CLI framework adapters, enabling support for multiple CLI frameworks (Click, Typer, argparse, etc.) through a common abstraction.
Classes¶
CLIAdapter
¶
Bases: Protocol
Protocol for CLI framework adapters.
Adapters convert framework-agnostic CommandInfo objects into framework-specific CLI commands and groups. This allows the hub to work with any CLI framework without tight coupling.
Currently provides ClickAdapter. Custom adapters for other frameworks (Typer, argparse) can be implemented by following the CLIAdapter protocol.
See: docs/guide/advanced/integration-patterns.md#custom-cli-adapters
Examples:
>>> from provide.foundation.cli import get_cli_adapter
>>> adapter = get_cli_adapter('click')
>>> command = adapter.build_command(command_info)
Functions¶
build_command
¶
Build framework-specific command from CommandInfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
CommandInfo
|
Framework-agnostic command information |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Framework-specific command object (e.g., click.Command) |
Raises:
| Type | Description |
|---|---|
CLIBuildError
|
If command building fails |
Source code in provide/foundation/cli/base.py
build_group
¶
build_group(
name: str,
commands: list[CommandInfo] | None = None,
registry: Registry | None = None,
**kwargs: Any,
) -> Any
Build framework-specific command group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Group name |
required |
commands
|
list[CommandInfo] | None
|
List of command names to include (None = all from registry) |
None
|
registry
|
Registry | None
|
Command registry (defaults to global) |
None
|
**kwargs
|
Any
|
Framework-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Framework-specific group object (e.g., click.Group) |
Raises:
| Type | Description |
|---|---|
CLIBuildError
|
If group building fails |
Source code in provide/foundation/cli/base.py
ensure_parent_groups
¶
Ensure all parent groups in path exist.
Creates missing parent groups in the registry. For example, if parent_path is "db.migrate", ensures both "db" and "db.migrate" groups exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_path
|
str
|
Dot-notation path to parent (e.g., "db.migrate") |
required |
registry
|
Registry
|
Command registry to update |
required |