owmeta_core.cli_command_wrapper module¶
- exception owmeta_core.cli_command_wrapper.CLIUserError[source]¶
Bases:
ExceptionAn error which the user would have to correct.
Typically caused by invalid user input
- class owmeta_core.cli_command_wrapper.CLIAppendAction(mapper, key, index=-1, mapped_name=None, *args, **kwargs)[source]¶
Bases:
CLIStoreActionExtends CLIStoreAction to append to a set of accumulated values
Used for recording a
dict- Parameters
- mapper
CLIArgMapper CLI argument to Python mapper
- key
str Indicates what kind of argument is being mapped. One of
INSTANCE_ATTRIBUTE,METHOD_NAMED_ARG,METHOD_KWARGS,METHOD_NARGS- index
int Argument index. Used for maintaining the order of arguments when passed to the runner
- mapped_name
str The name to map to. optional.
- *args
passed to
Action- **kwargs
passed to
Action
- mapper
- class owmeta_core.cli_command_wrapper.CLIArgMapper[source]¶
Bases:
objectStores mappings for arguments and maps them back to the part of the object they come from
- apply(runner)[source]¶
Applies the collected arguments to the runner by calling methods and traversing the object attributes as required
- Parameters
- runner
object Target of the command and source of argument and method names
- runner
See also
CLICommandWrapperaccepts a runner argument in its
__init__method
- runners¶
Mapping from subcommand names to functions which run for them
- class owmeta_core.cli_command_wrapper.CLICommandWrapper(runner, mapper=None, hints=None, hints_map=None, program_name=None)[source]¶
Bases:
objectWraps an object such that it can be used in a command line interface
- Parameters
- runner
object An object that provides the methods to be invoked
- mapper
CLIArgMapper Stores the arguments and associated runners for the command. A mapper is created if none is provided. optional
- hints
dict A multi-level dict describing how certain command line arguments get turned into attributes and method arguments. If
hintsis not provided, the hints are looked up by the runner’s fully-qualified class name inhints_map. optional- hints_map
dict A multi-level dict describing how certain command line arguments get turned into attributes and method arguments. Defaults to
CLI_HINTS. optional- program_name
str The name of the top-level program. Uses
sys.argv[0]if not provided. optional
- runner
- extract_args(val)[source]¶
Extract arguments from the method or class docstring
In the return value (see below), the
summaryis astrused in listing out sub-commands. Thedetailis for the sub-command usage information and should, generally, include thesummary. Theparamsare a listParamInfoobjects describing the parameters.
- main(args=None, argument_callback=None, argument_namespace_callback=None)[source]¶
Runs in a manner suitable for being the ‘main’ method for a command line interface: parses arguments (as would be done with the result of
parser) from sys.argv or the provided args list and executes the commands specified therein- Parameters
- args
list the argument list to parse. optional
- argument_callback
callable() a callback to add additional arguments to the command line. optional
- argument_namespace_callback
callable() a callback to handle the parsed arguments to the command line. optional
- args
- parser(parser=None)[source]¶
Generates the argument parser’s arguments
- Parameters
- parser
argparse.ArgumentParser The parser to add the arguments to. optional: will create a parser if none is given
- parser
- class owmeta_core.cli_command_wrapper.CLIStoreAction(mapper, key, index=-1, mapped_name=None, *args, **kwargs)[source]¶
Bases:
ActionInteracts with the CLIArgMapper
- Parameters
- mapper
CLIArgMapper CLI argument to Python mapper
- key
str Indicates what kind of argument is being mapped. One of
INSTANCE_ATTRIBUTE,METHOD_NAMED_ARG,METHOD_KWARGS,METHOD_NARGS- index
int Argument index. Used for maintaining the order of arguments when passed to the runner
- mapped_name
str The name to map to. optional.
- *args
passed to
Action- **kwargs
passed to
Action
- mapper
- class owmeta_core.cli_command_wrapper.CLIStoreTrueAction(*args, **kwargs)[source]¶
Bases:
CLIStoreActionAction for storing
Truewhen a given option is provided- Parameters
- *args
passed to
CLIStoreAction- **kwargs
passed to
CLIStoreAction
- class owmeta_core.cli_command_wrapper.CLISubCommandAction(mapper, *args, **kwargs)[source]¶
Bases:
_SubParsersActionAction for sub-commands
Extends the normal action for sub-parsers to record the subparser name in a mapper
- Parameters
- mapper
CLIArgMapper CLI argument to Python mapper
- *args
Passed on to
argparse._SubParsersAction- **kwargs
Passed on to
argparse._SubParsersAction
- mapper
- owmeta_core.cli_command_wrapper.ARGUMENT_TYPES = {'int': <class 'int'>}¶
Map from parameter types to type constructors for parsing arguments