cmdtools.ext¶
cmdtools.ext.command¶
- class cmdtools.ext.command.Command(name: str, aliases: List[str] | None = None)¶
Bases:
BaseCommandA command struct or class.
- Parameters:
name (str) – The name of the command.
aliases (List[str]) – The aliases of the command.
- property aliases: List[str]¶
gets the command aliases if set.
- class cmdtools.ext.command.Group(name: str, commands: List[Command] | None = None)¶
Bases:
ContainerA group based container class.
- Parameters:
name (str) – The group name
commands (List[Command]) – List of command structs or classes.
- add_option(name: str, *, default: ~typing.Any | None = None, modifier: ~cmdtools.callback.option.OptionModifier = OptionModifier.NoModifier, type: ~typing.Type[int | float | str | bool] = <class 'str'>)¶
Adds an option to callback.
- Parameters:
name (str) – The option name.
default (str) – Default value if argument is not specified.
modifier (OptionModifier) – The option modifier, some modifier used to modify the value.
type (BasicType) – Convert the value to specified type.
- Raises:
TypeError – When adding option to non Command instance.
- command(name: str = '', *, aliases: List[str] | None = None)¶
assigns the target command struct or class to the container.
- Parameters:
name (str) – The name of the command
aliases (List[str]) – The command aliases.
cmdtools.ext.file¶
- class cmdtools.ext.file.ModuleLoader(fpath: str, *, load_classes: bool = True)¶
Bases:
ContainerA command module loader class.
- Parameters:
fpath (str) – Path to the module.
load_classes (bool) – Loads defined class type commands if true, otherwise loads the module as a
Command.
- Raises:
If failed to load module. - If the module failed to initialized. - If the callback loaded is not a function type.
TypeError – If aliases is not a list, when loading module as command file
cmdtools.ext.param¶
- exception cmdtools.ext.param.ParameterParsingError(message: str, name: str = '')¶
Bases:
CmdBaseException
- cmdtools.ext.param.apply_params(command, options)¶
Apply parsed parameters to command options.
- Parameters:
command (Command) – Source of command arguments.
options (dict) – The target command options.
- cmdtools.ext.param.parse_params(args)¶
Parse command arguments into parameters and positional arguments.
- Parameters:
args (list) – List of command arguments.
- Return type:
A tuple containing parameters and positional arguments.