Skip to content

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_command(info: CommandInfo) -> Any

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
def build_command(self, info: CommandInfo) -> Any:
    """Build framework-specific command from CommandInfo.

    Args:
        info: Framework-agnostic command information

    Returns:
        Framework-specific command object (e.g., click.Command)

    Raises:
        CLIBuildError: If command building fails

    """
    ...
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
def build_group(
    self,
    name: str,
    commands: list[CommandInfo] | None = None,
    registry: Registry | None = None,
    **kwargs: Any,
) -> Any:
    """Build framework-specific command group.

    Args:
        name: Group name
        commands: List of command names to include (None = all from registry)
        registry: Command registry (defaults to global)
        **kwargs: Framework-specific options

    Returns:
        Framework-specific group object (e.g., click.Group)

    Raises:
        CLIBuildError: If group building fails

    """
    ...
ensure_parent_groups
ensure_parent_groups(
    parent_path: str, registry: Registry
) -> None

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
Source code in provide/foundation/cli/base.py
def ensure_parent_groups(self, parent_path: str, registry: Registry) -> None:
    """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.

    Args:
        parent_path: Dot-notation path to parent (e.g., "db.migrate")
        registry: Command registry to update

    """
    ...