← GDG /

#044 gdtest_cli_nested

#044 gdtest_cli_nested OK CONFIG
Nested Click groups with subcommands
Click CLI with nested groups: main command โ†’ task group (run, list) and config group (show, set). The CLI Reference should show the multi-level command hierarchy with subgroups. The API Reference should show Engine (class) and run_task (function).
View Site → Build Log ๐Ÿงช Test Coverage

Build Mode

● Has great-docs.yml

This package ships a pre-supplied config. The great-docs init step is skipped and great-docs build uses the spec-defined configuration directly. Tests specific config options and their rendered output.

Dimensions

A1 B1 C1 D1 E1 E6 F6 G1 H7
A1Flat layoutlayout
B1Explicit __all__exports
C1Functions onlyobjects
D1NumPydocstrings
E1E1
E6No directivesdirectives
F6No user guideuser_guide
G1README.mdlanding
H7No extrasextras

Source Files

๐Ÿ“ gdtest_cli_nested/
๐Ÿ“„ __init__.py
"""A package with nested Click CLI groups."""

__version__ = "0.1.0"
__all__ = ["Engine", "run_task"]


class Engine:
    """
    A task execution engine.

    Parameters
    ----------
    workers
        Number of worker threads.
    """

    def __init__(self, workers: int = 4):
        self.workers = workers

    def execute(self, task: str) -> bool:
        """
        Execute a named task.

        Parameters
        ----------
        task
            Name of the task.

        Returns
        -------
        bool
            True if successful.
        """
        return True


def run_task(name: str, dry_run: bool = False) -> str:
    """
    Run a task by name.

    Parameters
    ----------
    name
        The task name.
    dry_run
        If True, simulate without executing.

    Returns
    -------
    str
        Task result message.
    """
    return f"{'[DRY RUN] ' if dry_run else ''}Ran: {name}"
๐Ÿ“„ cli.py
"""Nested CLI entry point using Click groups."""

import click


@click.group()
@click.version_option()
def cli():
    """gdtest-cli-nested: A nested command-line tool."""
    pass


@cli.group()
def task():
    """Manage tasks."""
    pass


@task.command()
@click.argument("name")
@click.option("--dry-run", is_flag=True, help="Simulate without executing.")
def run(name: str, dry_run: bool) -> None:
    """Run a specific task."""
    click.echo(f"Running task: {name}")


@task.command()
def list():
    """List all available tasks."""
    click.echo("task1\ntask2\ntask3")


@cli.group()
def config():
    """Manage configuration."""
    pass


@config.command()
@click.argument("key")
def get(key: str) -> None:
    """Get a configuration value."""
    click.echo(f"Config[{key}]")


@config.command()
@click.argument("key")
@click.argument("value")
def set(key: str, value: str) -> None:
    """Set a configuration value."""
    click.echo(f"Set {key}={value}")
๐Ÿ“„ README.md
# gdtest-cli-nested

A test package with nested Click CLI groups.
๐Ÿ“„ great-docs.yml
cli:
  enabled: true