This module provides tools for handling command-line arguments for a Krux application.
Krux applications use argparse for parsing command-line options. The add_*_args functions in this module all expect to be called with an instance of argparse.ArgumentParser, a subclass, or an object that follows the same interface.
argparse is part of the standard library in Python 3.x, but Krux uses Python 2.6, so you will need to add it to your requirements.pip file:
argparse==1.2.1
Usage:
from krux.cli import get_parser, Application
if __name__ == '__main__':
### functional
parser = get_parser(description = 'My Krux CLI App')
### OO
app = Application(name = 'My Krux CLI App')
parser = app.parser
This error is only raised if the application is expected to exit. It should never be caught.
Krux base class for CLI applications
Parameters: | name – name of your CLI application |
---|
Wraps object and sets up CLI argument parsing, stats and logging.
Parameters: | name (string) – name of the application. Should be unique to Krux |
---|
(required)
Parameters: | parser – The CLI parser. Defaults to |
---|
Any additional CLI arguments that (super) classes might want to add. This method is overridable.
Adds the given function as an exit hook. The function will be called with the given positional and keyword arguments when the application’s exit() method is called.
Add logging-related command-line arguments to the given parser.
Logging arguments are added to the ‘logging’ argument group which is created if it doesn’t already exist.
Parameters: | parser – parser instance to which the arguments will be added |
---|
Add stats-related command-line arguments to the given parser.
Parameters: | parser – parser instance to which the arguments will be added |
---|
Return an argument group based on the group name.
This will return an existing group if it exists, or create a new one.
Parameters: |
|
---|
Run setup and return an argument parser for Krux applications
Parameters: |
---|
All other keywords are passed verbatim to argparse.ArgumentParser