class monolith.cli.Parser(*args, **kwargs)
Subclass of argparse.ArgumentParser providing more control over output
class monolith.cli.SimpleExecutionManager(program, commands)
Returns dictionary with commands given during construction. If value is
a string, it would be converted into proper class pointer.
class monolith.cli.ExecutionManager(argv=None, stderr=None, stdout=None)
If completion is enabled, this method would write to self.stdout
completion words separated with space.
Runs a command.
- cmd – command to run (key at the registry)
- argv – arguments that would be passed to the command
Executes command based on given arguments.
Returns commands stored in the registry (sorted by name).
Returns dictionary (name / Command or string pointing at the
Returns monolith.cli.Parser instance for this
Returns usage text of the main application parser.
alias of Parser
register(name, Command, force=False)
Registers given Command (as given name) at this
- name – name in the registry under which given Command
should be stored.
- Command – should be subclass of
- force – Forces registration if set to True - even if another
command was already registered, it would be overridden and no
execption would be raised. Defaults to False.
If another command was already registered
under given name.
class monolith.cli.BaseCommand(prog_name=None, stdout=None)
Base command class that should be subclassed by concrete commands.
- help: Help description for this command. Defaults to empty string.
- args: List of Argument instances. Defaults to empty list.
- prog_name: Program name of ExecutionManager within which this
command is run. Defaults to None.
- stdout: File-like object. Command should write to it. Defaults to
Returns list of Argument instances for the parser. By default,
it returns self.args.
Handles given namespace and executes command. Should be overridden
Performs actions once this command is registered within given
manager. By default it does nothing.
This would be called when command is registered by ExecutionManager
after arguments from get_args are processed.
Default implementation does nothing.
- parser – Global argparser.ArgumentParser
- cmdparser – Subparser related with this command
class monolith.cli.LabelCommand(prog_name=None, stdout=None)
Command that works on given position arguments (labels). By default, at
least one label is required. This is controlled by labels_required
- labels_required: If True, at least one label is required,
otherwise no positional arguments could be given. Defaults to True.
Returns argument for labels.
Handles given namespace by calling handle_label method
for each given label.
Handles single label. Should be overridden at subclass.
Performs some action if no lables were given. By default it does
class monolith.cli.SingleLabelCommand(prog_name=None, stdout=None)
Command that works on given positional argument (label).
- label_default_value: If no label were given, this would be default
value that would be passed to namespace. Defaults to None.
Returns argument for label.
Calls handle_label method for given label.
Handles label. Should be overridden at subclass.