← GDG /

#046 gdtest_cli_typer

#046 gdtest_cli_typer OK CONFIG
Typer CLI with a nested sub-app and CLI docs enabled
A package whose CLI is built with Typer (which vendors its own copy of Click) and cli.enabled=true in config. The sidebar should show a CLI Reference section documenting the Typer commands: top-level format and version commands, plus a nested db group (clear, info). The API Reference should show Formatter (class) and format_text (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_typer/
๐Ÿ“„ __init__.py
"""A package with Typer CLI support."""

__version__ = "0.1.0"
__all__ = ["Formatter", "format_text"]


class Formatter:
    """
    A text formatter.

    Parameters
    ----------
    style
        The formatting style to use.
    """

    def __init__(self, style: str = "default"):
        self.style = style

    def apply(self, text: str) -> str:
        """
        Apply formatting to text.

        Parameters
        ----------
        text
            The text to format.

        Returns
        -------
        str
            Formatted text.
        """
        return text


def format_text(text: str, style: str = "default") -> str:
    """
    Format text with a given style.

    Parameters
    ----------
    text
        The text to format.
    style
        The style to apply.

    Returns
    -------
    str
        Formatted text.
    """
    return Formatter(style).apply(text)
๐Ÿ“„ cli.py
"""CLI entry point using Typer."""

import typer

app = typer.Typer(help="Format and manage text with the gdtest-cli-typer tool.")

db_app = typer.Typer(help="Manage the formatting cache database.")
app.add_typer(db_app, name="db")


@app.command()
def format(
    text: str,
    style: str = typer.Option("default", "--style", "-s", help="Formatting style."),
    verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output."),
) -> None:
    """Format TEXT using the configured formatter."""
    if verbose:
        typer.echo(f"Formatting with style: {style}")
    typer.echo(text)


@app.command()
def version() -> None:
    """Show the tool version and exit."""
    typer.echo("0.1.0")


@db_app.command()
def clear(force: bool = typer.Option(False, "--force", help="Skip confirmation.")) -> None:
    """Clear the formatting cache."""
    typer.echo("cleared" if force else "confirm?")


@db_app.command()
def info() -> None:
    """Show cache database info."""
    typer.echo("cache info")
๐Ÿ“„ README.md
# gdtest-cli-typer

A test package with Typer CLI support.
๐Ÿ“„ great-docs.yml
cli:
  enabled: true