Opster API

opster.command(options=None, usage=None, name=None, shortlist=False, hide=False)

Decorator to mark function to be used for command line processing.

All arguments are optional:

  • options: options in format described in docs. If not supplied, will be determined from function.
  • usage: usage string for function, replaces %name with name of program or subcommand. In case if it’s subcommand and %name is not present, usage is prepended by name
  • name: used for multiple subcommands. Defaults to wrapped function name
  • shortlist: if command should be included in shortlist. Used only with multiple subcommands
  • hide: if command should be hidden from help listing. Used only with multiple subcommands, overrides shortlist
opster.dispatch(args=None, cmdtable=None, globaloptions=None, middleware=<function <lambda> at 0x1f09230>)

Dispatch command arguments based on subcommands.

  • args: list of arguments, default: sys.argv[1:]
  • cmdtable: dict of commands in format described below. If not supplied, will use functions decorated with @command.
  • globaloptions: list of options which are applied to all commands, will contain --help option at least.
  • middleware: global decorator for all commands.

cmdtable format description:

{'name': (function, options, usage)}
  • name is the name used on command-line. Can contain aliases (separate them with |), pointer to a fact that this command should be displayed in short help (start name with ^), or to a fact that this command should be hidden (start name with ~)
  • function is the actual callable
  • options is options list in format described in docs
  • usage is the short string of usage

Previous topic

Opster usage

This Page