owmeta_core.cli_command_wrapper module

exception owmeta_core.cli_command_wrapper.CLIUserError[source]

Bases: Exception

An 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: CLIStoreAction

Extends CLIStoreAction to append to a set of accumulated values

Used for recording a dict

Parameters
mapperCLIArgMapper

CLI argument to Python mapper

keystr

Indicates what kind of argument is being mapped. One of INSTANCE_ATTRIBUTE, METHOD_NAMED_ARG, METHOD_KWARGS, METHOD_NARGS

indexint

Argument index. Used for maintaining the order of arguments when passed to the runner

mapped_namestr

The name to map to. optional.

*args

passed to Action

**kwargs

passed to Action

class owmeta_core.cli_command_wrapper.CLIArgMapper[source]

Bases: object

Stores 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
runnerobject

Target of the command and source of argument and method names

See also

CLICommandWrapper

accepts 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: object

Wraps an object such that it can be used in a command line interface

Parameters
runnerobject

An object that provides the methods to be invoked

mapperCLIArgMapper

Stores the arguments and associated runners for the command. A mapper is created if none is provided. optional

hintsdict

A multi-level dict describing how certain command line arguments get turned into attributes and method arguments. If hints is not provided, the hints are looked up by the runner’s fully-qualified class name in hints_map. optional

hints_mapdict

A multi-level dict describing how certain command line arguments get turned into attributes and method arguments. Defaults to CLI_HINTS. optional

program_namestr

The name of the top-level program. Uses sys.argv[0] if not provided. optional

extract_args(val)[source]

Extract arguments from the method or class docstring

In the return value (see below), the summary is a str used in listing out sub-commands. The detail is for the sub-command usage information and should, generally, include the summary. The params are a list ParamInfo objects describing the parameters.

Parameters
valobject

The object with the documentation

Returns
tuple

a triple, (summary, detail, params)

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
argslist

the argument list to parse. optional

argument_callbackcallable()

a callback to add additional arguments to the command line. optional

argument_namespace_callbackcallable()

a callback to handle the parsed arguments to the command line. optional

parser(parser=None)[source]

Generates the argument parser’s arguments

Parameters
parserargparse.ArgumentParser

The parser to add the arguments to. optional: will create a parser if none is given

class owmeta_core.cli_command_wrapper.CLIStoreAction(mapper, key, index=-1, mapped_name=None, *args, **kwargs)[source]

Bases: Action

Interacts with the CLIArgMapper

Parameters
mapperCLIArgMapper

CLI argument to Python mapper

keystr

Indicates what kind of argument is being mapped. One of INSTANCE_ATTRIBUTE, METHOD_NAMED_ARG, METHOD_KWARGS, METHOD_NARGS

indexint

Argument index. Used for maintaining the order of arguments when passed to the runner

mapped_namestr

The name to map to. optional.

*args

passed to Action

**kwargs

passed to Action

class owmeta_core.cli_command_wrapper.CLIStoreTrueAction(*args, **kwargs)[source]

Bases: CLIStoreAction

Action for storing True when 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: _SubParsersAction

Action for sub-commands

Extends the normal action for sub-parsers to record the subparser name in a mapper

Parameters
mapperCLIArgMapper

CLI argument to Python mapper

*args

Passed on to argparse._SubParsersAction

**kwargs

Passed on to argparse._SubParsersAction

owmeta_core.cli_command_wrapper.ARGUMENT_TYPES = {'int': <class 'int'>}

Map from parameter types to type constructors for parsing arguments