Skip to content

Adapter

provide.foundation.cli.click.adapter

Click CLI adapter implementation.

Classes

ClickAdapter

Click framework adapter.

Implements the CLIAdapter protocol for the Click framework, converting framework-agnostic CommandInfo objects to Click commands and groups.

Examples:

>>> adapter = ClickAdapter()
>>> command = adapter.build_command(command_info)
>>> isinstance(command, click.Command)
True
Functions
build_command
build_command(info: CommandInfo) -> click_types.Command

Build Click command from CommandInfo.

Parameters:

Name Type Description Default
info CommandInfo

Framework-agnostic command information

required

Returns:

Type Description
Command

Click Command object

Raises:

Type Description
CLIBuildError

If command building fails

Source code in provide/foundation/cli/click/adapter.py
def build_command(self, info: CommandInfo) -> click_types.Command:
    """Build Click command from CommandInfo.

    Args:
        info: Framework-agnostic command information

    Returns:
        Click Command object

    Raises:
        CLIBuildError: If command building fails

    """
    return build_click_command_from_info(info)
build_group
build_group(
    name: str,
    commands: list[CommandInfo] | None = None,
    registry: Registry | None = None,
    **kwargs: Any
) -> click_types.Group

Build Click group with commands.

Parameters:

Name Type Description Default
name str

Group name

required
commands list[CommandInfo] | None

List of CommandInfo objects (or None to use registry)

None
registry Registry | None

Command registry

None
**kwargs Any

Additional Click Group options

{}

Returns:

Type Description
Group

Click Group object

Raises:

Type Description
CLIBuildError

If group building fails

Source code in provide/foundation/cli/click/adapter.py
def build_group(
    self,
    name: str,
    commands: list[CommandInfo] | None = None,
    registry: Registry | None = None,
    **kwargs: Any,
) -> click_types.Group:
    """Build Click group with commands.

    Args:
        name: Group name
        commands: List of CommandInfo objects (or None to use registry)
        registry: Command registry
        **kwargs: Additional Click Group options

    Returns:
        Click Group object

    Raises:
        CLIBuildError: If group building fails

    """
    # If commands is a list of CommandInfo, extract names
    command_names = None
    if commands:
        command_names = [cmd.name for cmd in commands]

    return create_command_group(
        name=name,
        commands=command_names,
        registry=registry,
        **kwargs,
    )
ensure_parent_groups
ensure_parent_groups(
    parent_path: str, registry: Registry
) -> None

Ensure all parent groups in path exist.

Parameters:

Name Type Description Default
parent_path str

Dot-notation path (e.g., "db.migrate")

required
registry Registry

Command registry to update

required
Source code in provide/foundation/cli/click/adapter.py
def ensure_parent_groups(self, parent_path: str, registry: Registry) -> None:
    """Ensure all parent groups in path exist.

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

    """
    ensure_parent_groups(parent_path, registry)

Functions