ArgsDataClass
Module: terminaltexteffects.utils.argsdataclass
This module defines classes and functions designed to work with the argparse library and enable typed arguments to support interacting with terminaltexteffects as both a command line tool and a library.
The ArgField class extends the built-in Field class to include additional metadata specific to command-line arguments. This metadata includes the command-line argument name, help text, type parser, metavar, nargs, action, required status, and choices.
The ArgParserDescriptor dataclass contains required attributes to call the "add_parser()" method of the _argparse._SubParsersAction class.
The ArgsDataClass dataclass represents command-line arguments and provides methods for handling them. It does not define any fields itself but is meant to be subclassed, with subclasses defining their own fields to represent the command-line arguments they expect.
Classes:
Name | Description |
---|---|
ArgField |
A subclass of the dataclasses.Field class that represents a command-line argument. |
ArgParserDescriptor |
A dataclass that contains required attributes to call "add_parser()" method of the _argparse._SubParsersAction" class. |
ArgsDataClass |
A dataclass that represents command-line arguments and provides methods for handling them. |
ArgField
Bases: Field
A subclass of the dataclasses.Field class that represents a command-line argument.
This class extends the built-in Field class to include additional metadata specific to command-line arguments. This metadata includes the command-line argument name, help text, type parser, metavar, nargs, action, required status, and choices.
The class also overrides the init method to handle the additional metadata and to set default values based on the 'action' attribute. If 'action' is "store_true", the default value is set to False. If 'action' is "store_false", the default value is set to True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd_name |
str | list[str]
|
The name or names of the command-line argument. |
required |
help |
str
|
The help text to display for the argument. |
required |
type_parser |
Any
|
The validator to use to validate the argument. Defaults to None. |
None
|
metavar |
str | None
|
A name for the argument in usage messages. Defaults to None. |
None
|
nargs |
str | None
|
The number of command-line arguments that should be consumed. Defaults to None. |
None
|
action |
str | None
|
The basic type of action to be taken when this argument is encountered at the command line. Defaults to None. |
None
|
required |
bool
|
Whether or not the command-line option is required. Defaults to False. |
False
|
choices |
list[str | int] | None
|
A container of the allowable values for the argument. Defaults to None. |
None
|
default |
any
|
The value produced if the argument is absent from the command line. Defaults to MISSING. |
MISSING
|
default_factory |
any
|
A function that is called to provide the default value. Defaults to MISSING. |
MISSING
|
init |
bool
|
If true (the default), this field is included as a parameter to the generated init method. Defaults to True. |
True
|
repr |
bool
|
If true (the default), this field is included in the string returned by the generated repr method. Defaults to True. |
True
|
hash |
bool | None
|
This can be a bool or None. If true, this field is included in the generated hash method. Defaults to None. |
None
|
compare |
bool
|
If true (the default), this field is included in the generated equality and comparison methods (eq, gt, etc.). Defaults to True. |
True
|
kw_only |
bool
|
If true, this field must be passed as a keyword argument. Defaults to MISSING. |
MISSING
|
Source code in terminaltexteffects/utils/argsdataclass.py
ArgParserDescriptor
dataclass
This dataclass contains required attributes to call "add_parser()" method of _argparse._SubParsersAction" class
Source code in terminaltexteffects/utils/argsdataclass.py
ArgsDataClass
dataclass
A dataclass that represents command-line arguments and provides methods for handling them.
This class provides a structured way to define and work with command-line arguments. It uses Python's built-in dataclasses and the argparse module to parse command-line arguments and create an instance of the class from them.
Note
This class does not define any fields itself. Instead, it is meant to be subclassed, with subclasses defining their own fields to represent the command-line arguments they expect.
Source code in terminaltexteffects/utils/argsdataclass.py
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 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 |
|
argclass(name, help, description, epilog)
Decorator for providing required metadata to an "ArgDataClass"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name for parser or subparser |
required |
help |
str
|
help string for parser or subparser |
required |
description |
str
|
description string for parser or subparser |
required |
epilog |
str
|
epilog string for parser or subparser |
required |