Module with convenient function for defining user commands.
- lmi.scripts.common.command.helper.make_list_command(func, name=None, columns=None, verify_func=None, transform_func=None)¶
Create a command subclassed from LmiLister. Please refer to this class for detailed usage.
- func (string or callable) – Contents of CALLABLE property.
- name (string) – Optional name of resulting class. If not given, it will be made from the name of associated function.
- columns (tuple) – Contents of COLUMNS property.
- verify_func (callable) – Callable overriding py:meth:~.endpoint.LmiEndPointCommand.verify_options method.
- transform_func (callable) – Callable overriding transform_options() method.
Subclass of LmiLister.
- lmi.scripts.common.command.helper.register_subcommands(command_name, usage, command_map, fallback_command=None)¶
Create a multiplexer command (a node in a tree of commands).
- command_name (string) – Name of created command. The same as will be given on a command line.
- usage (string) – Usage string parseable by docopt.
- command_map (dictionary) – Dictionary of subcommands. Associates command names to their factories. It’s assigned to COMMANDS property.
- fallback_command (LmiEndPointCommand) – Command factory used when no command is given on command line.
Subclass of LmiCommandMultiplexer.
- lmi.scripts.common.command.helper.select_command(command_name, *args, **kwargs)¶
Create command selector that loads command whose requirements are met.
Example of invocation:
Hardware = select_command('Hardware', ("Openlmi-Hardware >= 0.4.2", "lmi.scripts.hardware.current.Cmd"), ("Openlmi-Hardware < 0.4.2" , "lmi.scripts.hardware.pre042.Cmd"), default=HwMissing )
Above example checks remote broker for OpenLMI-Hardware provider. If it is installed and its version is equal or higher than 0.4.2, command from current module will be used. For older registered versions command contained in pre042 module will be loaded. If hardware provider is not available, HwMissing command will be loaded instead.
Check out the grammer describing language used in these conditions at lmi.scripts.common.versioncheck.parser.
- args – List of pairs (condition, command) that are inspected in given order until single condition is satisfied. Associated command is then loaded. Command is either a reference to command class or path to it given as string. In latter case last dot divides module’s import path and command name.
- default – This command will be loaded when no condition from args is satisfied.