Defines base command class for all endpoint commands. Those having no children.

class lmi.scripts.common.command.endpoint.LmiEndPointCommand(*args, **kwargs)

Base class for any leaf command.

List of additional recognized properties:

CALLABLE : tuple
Associated function. Will be wrapped in LmiEndPointCommand.execute() method and will be accessible directly as a cmd.execute.dest property. It may be specified either as a string in form "<module_name>:<callable>" or as a reference to callable itself.
String appended to every option parsed by docopt having list as an associated value. It defaults to empty string. This modification is applied before calling LmiEndPointCommand.verify_options() and LmiEndPointCommand.transform_options().
FORMATTER : callable
Default formatter factory for instances of given command. This factory accepts an output stream as the only parameter and returns an instance of Formatter.
Using metaclass:
classmethod dest_pos_args_count()

Number of positional arguments the associated function takes from command. These arguments are created by the command alone – they do not belong to options in usage string. Function can take additional positional arguments that need to be covered by usage string.

Return type:integer
execute(*args, **kwargs)

Subclasses must override this method to pass given arguments to command library function. This function shall be specified in CALLABLE property.


Return instance of default formatter.

Return type:Formatter

Subclasses shall override this method to provide default formatter factory for printing output.

Returns:Subclass of basic formatter.

This method can be use to render and print results with default formatter.

Parameters:data – Is an object expected by the produce_output() method of formatter.

Create options dictionary from input arguments, verify them, transform them, make positional and keyword arguments out of them and pass them to process_session().

Parameters:args (list) – List of command arguments.
Returns:Exit code of application.
Return type:integer
run_with_args(args, kwargs)

Process end-point arguments and exit.

  • args (list) – Positional arguments to pass to associated function in command library.
  • kwargs (dictionary) – Keyword arguments as a dictionary.

Exit code of application.

Return type:



This method can be overriden in subclasses if options shall be somehow modified before passing them associated function.


Run after verify_options() method.

Parameters:options (dictionary) – Dictionary as returned by docopt parser.

This method can be overriden in subclasses to check, whether the options given on command line are valid. If any flaw is discovered, an LmiInvalidOptions exception shall be raised. Any returned value is ignored.


This is run before transform_options() method.

Parameters:options (dictionary) – Dictionary as returned by docopt parser.

Make a function parameter name out of option name. This replaces any character not suitable for python identificator with '_' and make the whole string lowercase.

Parameters:opt_name (string) – Option name.
Returns:Modified option name.
Return type:string

Convert option name from resulting docopt dictionary to a valid python identificator token used as function argument name.

Parameters:options (dictionary) – Dictionary returned by docopt call.
Returns:New dictionary with keys passable to function as argument names.
Return type:dictionary