Skip to main content

A library to parse CLI output into structured data.

Project description

CLInspector

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Discussions Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this month Package status PyUp

Read the documentation!

CLInspector Documentation

CLInspector is a library to introspect Python CLI applications and extract their command structure and parameters programmatically.

Usage

The main entry point is the get_cmd_info() function which analyzes a CLI application instance and returns a structured CommandInfo object:

from clinspector import get_cmd_info

command_info = get_cmd_info(cli_instance)

The function accepts CLI application instances from the following frameworks:

  • Typer - typer.Typer instances
  • Click - click.Group instances
  • Cleo - cleo.Application instances
  • Cappa - Classes decorated with @cappa.command
  • argparse - ArgumentParser instances

The extracted information is returned as a CommandInfo object containing:

CommandInfo Fields

  • name: str - Name of the command
  • description: str - Description/help text
  • usage: str - Formatted usage string
  • subcommands: dict[str, CommandInfo] - Nested subcommands
  • deprecated: bool - Whether command is marked as deprecated
  • epilog: str | None - Optional epilog text
  • hidden: bool - Whether command is hidden
  • params: list[Param] - List of command parameters

Param Fields

  • name: str - Parameter name
  • help: str | None - Help text
  • default: Any - Default value
  • opts: list[str] - Parameter options (e.g. ["-f", "--flag"])
  • required: bool - Whether parameter is required
  • is_flag: bool - Whether parameter is a flag
  • multiple: bool - Whether parameter accepts multiple values
  • nargs: int | str | None - Number of arguments accepted
  • envvar: str | None - Environment variable name
  • hidden: bool - Whether parameter is hidden
  • param_type_name: Literal["option", "parameter", "argument"] - Parameter type
  • type: dict[str, str] | None - Parameter type information
  • metavar: str | None - Display name in help text

You can access subcommands using dictionary syntax:

# Get info for "build" subcommand
build_info = command_info["build"]

# Access nested subcommand
nested_info = command_info["group"]["subcommand"]

The extracted information allows you to:

- Generate documentation automatically
- Build command completion
- Create wrappers and adapters
- Perform static analysis of CLI interfaces
- And more!

Example output for a click command:

```python
CommandInfo(
    name="cli",
    description="Example CLI tool",
    usage="cli [OPTIONS] COMMAND [ARGS]...",
    params=[
        Param(name="verbose", help="Enable verbose output", opts=["-v", "--verbose"])
    ],
    subcommands={
        "build": CommandInfo(
            name="build",
            description="Build the project",
            params=[...]
        )
    }
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clinspector-0.5.1.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clinspector-0.5.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file clinspector-0.5.1.tar.gz.

File metadata

  • Download URL: clinspector-0.5.1.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clinspector-0.5.1.tar.gz
Algorithm Hash digest
SHA256 9acd07850cfffd6058556b08c6bfa3a06fcd9068860e89d4fb8dbf10c93f5f78
MD5 453907b08a5ba89e1b47a1bd82997e0d
BLAKE2b-256 d4d7a3d33d1b5c7d5e6bb1e92744cc1948fd679ed189739ee09f8e4b43a5701b

See more details on using hashes here.

Provenance

The following attestation bundles were made for clinspector-0.5.1.tar.gz:

Publisher: build.yml on phil65/clinspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clinspector-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: clinspector-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clinspector-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b1d0f3391a648224ed173b675667639407fff832beb321d5e8d4f59ed829851
MD5 3f1f40fd3054ba59e068e1af01f048ed
BLAKE2b-256 f3bc43becb0eca643e8e99cb68363240780860b0ec35d4e797d9de95227a27af

See more details on using hashes here.

Provenance

The following attestation bundles were made for clinspector-0.5.1-py3-none-any.whl:

Publisher: build.yml on phil65/clinspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page