Skip to content

cli_app.cli.app

cli_app.cli.app

main

main(
    ctx,
    version=False,
    authors=False,
    verbose=False,
    output_format=OutputFormat.text,
)

Manage the main application state and top-level options like --version.

Source code in src/cli_app/cli/app.py
@app.callback()
def main(
    ctx: Context,
    version: Annotated[  # noqa: ARG001
        bool,
        Option(
            "--version",
            "-v",
            help="Show the application's version and exit.",
            callback=meta_callbacks.version_cb,
            is_eager=True,
        ),
    ] = False,
    authors: Annotated[  # noqa: ARG001
        bool,
        Option(
            "--authors",
            "-A",
            help="Show the application's authors contacts and exit.",
            callback=meta_callbacks.authors_cb,
            is_eager=True,
        ),
    ] = False,
    verbose: Annotated[
        bool,
        Option(
            "--verbose",
            "-V",
            help="Enable verbose (DEBUG) logging.",
        ),
    ] = False,
    output_format: Annotated[
        OutputFormat,
        Option(
            "--output-format",
            "-f",
            help="Output format.",
        ),
    ] = OutputFormat.text,
) -> None:
    """Manage the main application state and top-level options like --version."""
    ctx.ensure_object(dict)
    ctx.obj["output_format"] = output_format
    if verbose:
        root = logging.getLogger()
        root.setLevel(logging.DEBUG)
        for handler in root.handlers:
            handler.setLevel(logging.DEBUG)