clinspector
Class info¶
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| CommandInfo | clinspector.models.commandinfo | Framework-independent description of a CLI command and its subcommands. |
| Param | clinspector.models.param | Framework-independent description of a CLI parameter (option or argument). |
🛈 DocStrings¶
CLInspector: main package.
Introspect Python CLI apps (Typer, Click, Cleo, Cappa, Cyclopts, argparse) into structured data.
CommandInfo
dataclass
¶
Framework-independent description of a CLI command and its subcommands.
Source code in src/clinspector/models/commandinfo.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
callback
class-attribute
instance-attribute
¶
The framework callback for this command (not part of to_dict / comparisons).
deprecated
class-attribute
instance-attribute
¶
Whether this command is deprecated.
description
class-attribute
instance-attribute
¶
A description for this command.
params
class-attribute
instance-attribute
¶
params: list[Param] = dataclasses.field(default_factory=list)
A list of Params for this command.
subcommands
class-attribute
instance-attribute
¶
subcommands: dict[str, CommandInfo] = dataclasses.field(default_factory=dict)
A command-name->CommandInfo mapping containing all subcommands.
usage
class-attribute
instance-attribute
¶
A formatted string containing a formatted "usage string" (placeholder example)
__getitem__
¶
__getitem__(name: str) -> CommandInfo
__post_init__
¶
build_cli_command
¶
Build the command line parts for execution.
List / tuple values are repeated for options (--opt a --opt b) and
expanded for arguments. Integer values for counting flags repeat the flag,
False for flags with secondary options (--x/--no-x) emits the secondary one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
dict[str, Any] | None
|
Dictionary of parameter name to value mappings |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of command parts ready for subprocess execution |
Source code in src/clinspector/models/commandinfo.py
execute_callback
¶
Execute this command's callback with the given arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Arguments to pass to the callback |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Result of the callback function |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the command has no callback |
Source code in src/clinspector/models/commandinfo.py
execute_cli
¶
execute_cli(
args: dict[str, Any] | None = None,
capture_output: bool = False,
check: bool = True,
env: dict[str, str] | None = None,
) -> CompletedProcess[str]
Execute this command as a CLI process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
dict[str, Any] | None
|
Dictionary of parameter name to value mappings |
None
|
capture_output
|
bool
|
Whether to capture stdout/stderr |
False
|
check
|
bool
|
Whether to raise exception if command fails |
True
|
env
|
dict[str, str] | None
|
Environment variables to set for the process |
None
|
Returns:
| Type | Description |
|---|---|
CompletedProcess[str]
|
Completed process with results |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If check=True and process returns non-zero |
Source code in src/clinspector/models/commandinfo.py
from_dict
classmethod
¶
from_dict(data: dict[str, Any]) -> CommandInfo
Create a command tree from a dict (as returned by to_dict).
Source code in src/clinspector/models/commandinfo.py
to_dict
¶
Return a dict representation of this command tree (without callbacks).
Source code in src/clinspector/models/commandinfo.py
walk
¶
walk() -> Iterator[CommandInfo]
Iterate over this command and all (nested) subcommands, depth-first.
Param
dataclass
¶
Framework-independent description of a CLI parameter (option or argument).
Source code in src/clinspector/models/param.py
choices
class-attribute
instance-attribute
¶
List of valid choices for this parameter.
count
class-attribute
instance-attribute
¶
Whether the parameter increments an integer.
default
class-attribute
instance-attribute
¶
The default value of the parameter.
envvar
class-attribute
instance-attribute
¶
The environment variable name for this parameter.
expose_value
class-attribute
instance-attribute
¶
Whether value is passed onwards to the command callback and stored in context.
flag_value
class-attribute
instance-attribute
¶
Value used for this flag if enabled.
help
class-attribute
instance-attribute
¶
A formatted help text for this parameter.
is_option
property
¶
Whether this parameter is an option (as opposed to a positional argument).
metavar
class-attribute
instance-attribute
¶
How value is represented in the help page.
multiple
class-attribute
instance-attribute
¶
Whether the parameter is accepted multiple times and recorded.
nargs
class-attribute
instance-attribute
¶
The number of arguments this parameter matches. (Argparse may return * / ?)
opts
class-attribute
instance-attribute
¶
Options for this parameter.
param_type_name
class-attribute
instance-attribute
¶
Whether this parameter is an option or a positional argument.
prompt
class-attribute
instance-attribute
¶
Whether user is prompted for this parameter.
required
class-attribute
instance-attribute
¶
Whether the parameter is required.
secondary_opts
class-attribute
instance-attribute
¶
Secondary options for this parameter (e.g. --no-flag).
type
class-attribute
instance-attribute
¶
Name of the value type ("str", "int", "float", "bool", "path", ...).
get_cmd_info
¶
get_cmd_info(instance: Any, command: str | None = None) -> CommandInfo | None
Return a CommandInfo object for command of given instance.
Instance can be
- a Typer instance
- a click Command / Group instance
- a cleo Application instance
- a cappa command class
- a cyclopts App instance
- an ArgumentParser instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
A supported CLI instance |
required |
command
|
str | None
|
An optional subcommand to fetch info for. Nested subcommands can be
addressed with dot notation ( |
None
|
Returns:
| Type | Description |
|---|---|
CommandInfo | None
|
The command info, or None if the instance type is not supported. |
Source code in src/clinspector/introspect/__init__.py
parse_help_text
¶
parse_help_text(text: str) -> CommandInfo
Parse the --help output of a CLI program into a CommandInfo.
Recognized sections are options (Options:, optional arguments:, ...),
positional arguments (argparse subcommand lists included) and commands.
Subcommands are returned without params (their help pages are separate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The help text (ANSI color codes are stripped). |
required |
Source code in src/clinspector/introspect/help_text.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |