apps.utils.cli
Base classes used for building command line applications.
Module Contents
- class BaseParser
Bases:
argparse.ArgumentParserBase class for building commandline applications.
Child classes should implement the following:
The application commandline interface in the
__init__methodThe primary application logic in the
app_logicmethod
Unless set explicitly, the application description (
self.description) is pulled from the class docstring.- description = ''
- abstractmethod app_logic(args: argparse.Namespace) None
Logic to evaluate when executing the application
- Parameters:
args – Parsed command line arguments
- error(message: str) None
Handle errors and exit the application
This method mimics the parent class behavior except error messages are included in the raised SystemExit exception. This makes for easier testing/debugging.
- Parameters:
message – The error message
- Raises:
SystemExit – Every time the method is run
- print_help_if_no_args() None
Print help text and exit if no arguments were provided but some are required.
- classmethod execute(args: List[str] | None = None) None
Parse command line arguments and execute the application
- Parameters:
args – Optionally parse the given arguments instead of reading STDIN