Introspect
ArgumentSchema
dataclass
A data class for defining the schema of a CLI argument.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the argument. |
type |
str
|
The type of the argument. |
required |
bool
|
Whether the argument is required. |
key |
str
|
The key for the argument. |
default |
MultiValueParamData | None
|
The default value of the argument. |
choices |
Sequence[str] | None
|
The choices for the argument. |
multiple |
bool
|
Whether the argument can have multiple values. |
nargs |
int
|
The number of arguments for the argument. |
Source code in src/guigaga/introspect.py
CommandSchema
dataclass
A data class for defining the schema of a CLI command.
Attributes:
Name | Type | Description |
---|---|---|
name |
CommandName
|
The name of the command. |
function |
Callable[..., Any | None]
|
The function to execute when the command is called. |
key |
str
|
The key for the command. |
docstring |
str | None
|
The docstring for the command. |
options |
list[OptionSchema]
|
The options for the command. |
arguments |
list[ArgumentSchema]
|
The arguments for the command. |
subcommands |
dict['CommandName', 'CommandSchema']
|
The subcommands for the command. |
parent |
CommandSchema | None
|
The parent command. |
is_group |
bool
|
Whether the command is a group command. |
Source code in src/guigaga/introspect.py
path_from_root: list['CommandSchema']
property
Gets the path from the root command to the current command.
Returns:
Type | Description |
---|---|
list['CommandSchema']
|
list[CommandSchema]: A list of CommandSchema instances representing the path from the root command to the current command. |
MultiValueParamData
dataclass
A data class for storing multiple values from a command line interface (CLI) option.
Attributes:
Name | Type | Description |
---|---|---|
values |
list[tuple[int | float | str]]
|
A list of tuples containing the values. |
Source code in src/guigaga/introspect.py
process_cli_option(value)
staticmethod
Processes a CLI option value into a MultiValueParamData instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Any
|
The value to process. |
required |
Returns:
Name | Type | Description |
---|---|---|
MultiValueParamData |
'MultiValueParamData'
|
A MultiValueParamData instance containing the processed value. |
Examples:
>>> MultiValueParamData.process_cli_option(('a', 'b', 'c'))
MultiValueParamData(values=[('a', 'b', 'c')])
Source code in src/guigaga/introspect.py
OptionSchema
dataclass
A data class for defining the schema of a CLI option.
Attributes:
Name | Type | Description |
---|---|---|
name |
list[str]
|
The names of the option. |
type |
ParamType
|
The type of the option. |
default |
MultiValueParamData | None
|
The default value of the option. |
required |
bool
|
Whether the option is required. |
is_flag |
bool
|
Whether the option is a flag. |
is_boolean_flag |
bool
|
Whether the option is a boolean flag. |
flag_value |
Any
|
The value of the flag. |
opts |
list
|
Additional options. |
counting |
bool
|
Whether the option is counting. |
secondary_opts |
list
|
Secondary options. |
key |
str | tuple[str]
|
The key for the option. |
help |
str | None
|
The help text for the option. |
choices |
Sequence[str] | None
|
The choices for the option. |
multiple |
bool
|
Whether the option can have multiple values. |
multi_value |
bool
|
Whether the option is a multi-value option. |
nargs |
int
|
The number of arguments for the option. |
Source code in src/guigaga/introspect.py
__post_init__()
Post-initialization method for OptionSchema. Sets the multi_value attribute based on the type attribute.
generate_unique_id()
Generates a unique identifier.
Returns:
Name | Type | Description |
---|---|---|
str |
A unique identifier string. |
Examples:
introspect_click_app(app)
Introspect a Click application and build a data structure containing information about all commands, options, arguments, and subcommands, including the docstrings and command function references.
This function recursively processes each command and its subcommands (if any), creating a nested dictionary that includes details about options, arguments, and subcommands, as well as the docstrings and command function references.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app |
click.BaseCommand
|
The Click application's top-level group or command instance. |
required |
Returns:
Type | Description |
---|---|
dict[CommandName, CommandSchema]
|
Dict[str, CommandData]: A nested dictionary containing the Click application's |
dict[CommandName, CommandSchema]
|
structure. The structure is defined by the CommandData TypedDict and its related |
dict[CommandName, CommandSchema]
|
TypedDicts (OptionData and ArgumentData). |
Source code in src/guigaga/introspect.py
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|