command_creator.Command
- class command_creator.Command(sub_command: Command | None)
Bases:
ABCClass which represents a command-line command
Methods
__call__()This method must be implemented by subclasses, it is the method which is called to execute the command
This method may be implemented by subclasses in order to setup variables or post-process any user inputs
__init__(sub_command)create_parser([doc_mode])Create the argument parser for the Command using argparser library
execute()Execute the command and exit with the return code
from_args(args)Create a command from a list of arguments
parse_args([args])Parse the given args and create the command instance
Attributes
The override name of the (sub)command to use instead of the class-name
A dictionary mapping the sub-command name to the respective sub-command
The sub-command found during argument parsing.
- abstractmethod __call__() int
This method must be implemented by subclasses, it is the method which is called to execute the command
- __post_init__() None
This method may be implemented by subclasses in order to setup variables or post-process any user inputs
- classmethod _add_args(parser: ArgumentParser, doc_mode: bool = False) None
Add arguments to the parser
- Parameters:
parser (ArgumentParser) – The parser to add arguments to
doc_mode (bool) – Force the args to use metavars instead of options
- classmethod _add_sub_commands(parser: ArgumentParser, doc_mode: bool = False) None
Add sub-commands to the parser
- Parameters:
parser (ArgumentParser) – The parser to add sub-commands to
- cmd_name: ClassVar[str | None] = None
The override name of the (sub)command to use instead of the class-name
- classmethod create_parser(doc_mode: bool = False) ArgumentParser
Create the argument parser for the Command using argparser library
- Parameters:
doc_mode (bool, optional) – Whether to force meta-data use for prettier documentation. Defaults to False.
- Returns:
The argument-parser derived from the class definition
- Return type:
ArgumentParser
- classmethod execute() NoReturn
Execute the command and exit with the return code
- classmethod from_args(args: Namespace) CommandT
Create a command from a list of arguments
- Parameters:
args (list[str]) – The arguments to create the command from
- Returns:
The created command
- Return type:
CommandT
- classmethod parse_args(args: Sequence[str] | None = None) CommandT
Parse the given args and create the command instance
- Parameters:
cls (Type[CommandT]) – The command type to parse and create
args (Sequence[str] | None, optional) – The arg provided. Operates as ArgumentParser.parse_args. Defaults to None.
- Returns:
The command type provided as cls
- Return type:
CommandT