apps.utils.cli
Base classes used for building command line applications.
Module Contents
- class BaseParser
Bases:
argparse.ArgumentParser
Base 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_logic
method
Unless set explicitly, the application description (
self.description
) is pulled from the class docstring.- formatter_factory
- description
- program_name
- version_string
- abstract 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.If the application was called without any commandline arguments, the application help text is printed before exiting.
- Parameters:
message – The error message
- Raises:
SystemExit – Every time the method is run
- 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