A library to parse CLI output into structured data.
Project description
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:
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 commanddescription: str
- Description/help textusage: str
- Formatted usage stringsubcommands: dict[str, CommandInfo]
- Nested subcommandsdeprecated: bool
- Whether command is marked as deprecatedepilog: str | None
- Optional epilog texthidden: bool
- Whether command is hiddenparams: list[Param]
- List of command parameters
Param Fields
name: str
- Parameter namehelp: str | None
- Help textdefault: Any
- Default valueopts: list[str]
- Parameter options (e.g.["-f", "--flag"]
)required: bool
- Whether parameter is requiredis_flag: bool
- Whether parameter is a flagmultiple: bool
- Whether parameter accepts multiple valuesnargs: int | str | None
- Number of arguments acceptedenvvar: str | None
- Environment variable namehidden: bool
- Whether parameter is hiddenparam_type_name: Literal["option", "parameter", "argument"]
- Parameter typetype: dict[str, str] | None
- Parameter type informationmetavar: 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
Release history Release notifications | RSS feed
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.2.0.tar.gz
(14.5 kB
view details)
Built Distribution
File details
Details for the file clinspector-0.2.0.tar.gz
.
File metadata
- Download URL: clinspector-0.2.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36f5290d8951a7f9d2af3c4b9b5198eb18c0712226d9aa6f587aa2368712497b |
|
MD5 | 2c8aac000123ab53006cd6526fc13acf |
|
BLAKE2b-256 | bfec28bff66aafdfeac1859f4406be5182e688a26ee935ba91d39315d315009a |
File details
Details for the file clinspector-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: clinspector-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a8c331d3218f5565a208fb05b63905a2537a4b10c7c8e0e605f9211220ffc9 |
|
MD5 | 2bcb123222ba13614d7e3399a1709bbb |
|
BLAKE2b-256 | 3dd322a55d446b63060aa462e55905dc73b51980ae0b104db250f40596019840 |