Metadata-Version: 2.4
Name: clinspector
Version: 0.4.0
Summary: A library to parse CLI output into structured data.
Project-URL: Documentation, https://phil65.github.io/clinspector/
Project-URL: Source, https://github.com/phil65/clinspector
Project-URL: Issues, https://github.com/phil65/clinspector/issues
Project-URL: Discussions, https://github.com/phil65/clinspector/discussions
Project-URL: Code coverage, https://app.codecov.io/gh/phil65/clinspector
Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
License: MIT License
        
        Copyright (c) 2024, Philipp Temminghoff
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Documentation
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.12
Provides-Extra: all
Requires-Dist: cappa; extra == 'all'
Requires-Dist: cleo; extra == 'all'
Requires-Dist: click; extra == 'all'
Requires-Dist: typer; extra == 'all'
Provides-Extra: cappa
Requires-Dist: cappa; extra == 'cappa'
Provides-Extra: cleo
Requires-Dist: cleo; extra == 'cleo'
Provides-Extra: click
Requires-Dist: click; extra == 'click'
Provides-Extra: cyclopts
Requires-Dist: cyclopts; extra == 'cyclopts'
Provides-Extra: man-pages
Requires-Dist: hishel>=0.1.1; extra == 'man-pages'
Requires-Dist: httpx; extra == 'man-pages'
Provides-Extra: tldr
Requires-Dist: tldr; extra == 'tldr'
Provides-Extra: typer
Requires-Dist: typer; extra == 'typer'
Description-Content-Type: text/markdown

# CLInspector

[![PyPI License](https://img.shields.io/pypi/l/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Package status](https://img.shields.io/pypi/status/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Daily downloads](https://img.shields.io/pypi/dd/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Weekly downloads](https://img.shields.io/pypi/dw/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Monthly downloads](https://img.shields.io/pypi/dm/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Distribution format](https://img.shields.io/pypi/format/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Wheel availability](https://img.shields.io/pypi/wheel/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Python version](https://img.shields.io/pypi/pyversions/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Implementation](https://img.shields.io/pypi/implementation/clinspector.svg)](https://pypi.org/project/clinspector/)
[![Releases](https://img.shields.io/github/downloads/phil65/clinspector/total.svg)](https://github.com/phil65/clinspector/releases)
[![Github Contributors](https://img.shields.io/github/contributors/phil65/clinspector)](https://github.com/phil65/clinspector/graphs/contributors)
[![Github Discussions](https://img.shields.io/github/discussions/phil65/clinspector)](https://github.com/phil65/clinspector/discussions)
[![Github Forks](https://img.shields.io/github/forks/phil65/clinspector)](https://github.com/phil65/clinspector/forks)
[![Github Issues](https://img.shields.io/github/issues/phil65/clinspector)](https://github.com/phil65/clinspector/issues)
[![Github Issues](https://img.shields.io/github/issues-pr/phil65/clinspector)](https://github.com/phil65/clinspector/pulls)
[![Github Watchers](https://img.shields.io/github/watchers/phil65/clinspector)](https://github.com/phil65/clinspector/watchers)
[![Github Stars](https://img.shields.io/github/stars/phil65/clinspector)](https://github.com/phil65/clinspector/stars)
[![Github Repository size](https://img.shields.io/github/repo-size/phil65/clinspector)](https://github.com/phil65/clinspector)
[![Github last commit](https://img.shields.io/github/last-commit/phil65/clinspector)](https://github.com/phil65/clinspector/commits)
[![Github release date](https://img.shields.io/github/release-date/phil65/clinspector)](https://github.com/phil65/clinspector/releases)
[![Github language count](https://img.shields.io/github/languages/count/phil65/clinspector)](https://github.com/phil65/clinspector)
[![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/clinspector)](https://github.com/phil65/clinspector)
[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/clinspector)](https://github.com/phil65/clinspector)
[![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/clinspector)](https://github.com/phil65/clinspector)
[![Package status](https://codecov.io/gh/phil65/clinspector/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/clinspector/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyUp](https://pyup.io/repos/github/phil65/clinspector/shield.svg)](https://pyup.io/repos/github/phil65/clinspector/)

[Read the documentation!](https://phil65.github.io/clinspector/)

# 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:

```python
from clinspector import get_cmd_info

command_info = get_cmd_info(cli_instance)
```

The function accepts CLI application instances from the following frameworks:

- [Typer](https://typer.tiangolo.com/) - `typer.Typer` instances
- [Click](https://click.palletsprojects.com/) - `click.Group` instances
- [Cleo](https://cleo.readthedocs.io/) - `cleo.Application` instances
- [Cappa](https://github.com/DynamicArray/Cappa) - Classes decorated with `@cappa.command`
- [argparse](https://docs.python.org/3/library/argparse.html) - `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:

```python
# 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=[...]
        )
    }
)
```
