common.command.multiplexer

Defines command class used to nest multiple commands under one.

class lmi.scripts.common.command.multiplexer.LmiCommandMultiplexer(app, cmd_name, parent=None)

Base class for node commands. It consumes just part of command line arguments and passes the remainder to one of its subcommands.

Example usage:

class MyCommand(LmiCommandMultiplexer):
    '''
    My command description.

    Usage: %(cmd)s mycommand (subcmd1 | subcmd2)
    '''
    COMMANDS = {'subcmd1' : Subcmd1, 'subcmd2' : Subcmd2}

Where Subcmd1 and Subcmd2 are some other LmiBaseCommand subclasses. Documentation string must be parseable with docopt.

Recognized properties:

COMMANDS : dictionary
property will be translated to LmiCommandMultiplexer.child_commands() class method by MultiplexerMetaClass.

Using metaclass: meta.MultiplexerMetaClass.

classmethod child_commands()

Abstract class method, that needs to be implemented in subclass. This is done by associated meta-class, when defining a command with assigned COMMANDS property.

Returns:Dictionary of subcommand names with assigned command factories.
Return type:dictionary
classmethod fallback_command()

This is overriden by MultiplexerMetaClass when the FALLBACK_COMMAND gets processed.

Returns:Command factory invoked for missing command on command line.
Return type:LmiEndPointCommand
run(args)

Handle optional parameters, retrieve desired subcommand name and pass the remainder of arguments to it.

Parameters:args (list) – List of arguments with at least subcommand name.
run_subcommand(cmd_name, args)

Pass control to a subcommand identified by given name.

Parameters:
  • cmd_name (string) – Name of direct subcommand, whose run() method shall be invoked.
  • args (list) – List of arguments for particular subcommand.
Returns:

Application exit code.

Return type:

integer