CommandInfo
🛈 DocStrings¶
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.