API

Default API

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

Decorator to mark function to be used as command for CLI.

Usage:

from opster import command, dispatch

@command()
def run(argument,
        optionalargument=None,
        option=('o', 'default', 'help for option'),
        no_short_name=('', False, 'help for this option')):
    print argument, optionalargument, option, no_short_name

if __name__ == '__main__':
    run.command()

# or, if you want to have multiple subcommands:
if __name__ == '__main__':
    dispatch()
Optional arguments:
  • options: options in format described later. 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
  • aliases: list of aliases for command

If defined, options should be a list of 4-tuples in format:

(shortname, longname, default, help)

Where:

  • shortname is a single letter which can be used then as an option specifier on command line (like -a). Will be not used if contains falsy value (empty string, for example)
  • longname - main identificator of an option, can be used as on a command line with double dashes (like --longname)
  • default value for an option, type of it determines how option will be processed
  • help string displayed as a help for an option when asked to
opster.dispatch(args=None, cmdtable=None, globaloptions=None, middleware=None, scriptname=None)

Dispatch command line arguments using subcommands.

  • args: list of arguments, default: sys.argv[1:]

If you need more

class opster.Dispatcher(cmdtable=None, globaloptions=None, middleware=None)

Central object for command dispatching system.

  • cmdtable: dict of commands. Will be populated with functions, decorated with Dispatcher.command.
  • globaloptions: list of options which are applied to all commands, will contain --help option at least.
  • middleware: global decorator for all commands.
command(options=None, usage=None, name=None, shortlist=False, hide=False, aliases=())

Decorator to mark function to be used as command for CLI.

Usage:

from opster import command, dispatch

@command()
def run(argument,
        optionalargument=None,
        option=('o', 'default', 'help for option'),
        no_short_name=('', False, 'help for this option')):
    print argument, optionalargument, option, no_short_name

if __name__ == '__main__':
    run.command()

# or, if you want to have multiple subcommands:
if __name__ == '__main__':
    dispatch()
Optional arguments:
  • options: options in format described later. 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
  • aliases: list of aliases for command

If defined, options should be a list of 4-tuples in format:

(shortname, longname, default, help)

Where:

  • shortname is a single letter which can be used then as an option specifier on command line (like -a). Will be not used if contains falsy value (empty string, for example)
  • longname - main identificator of an option, can be used as on a command line with double dashes (like --longname)
  • default value for an option, type of it determines how option will be processed
  • help string displayed as a help for an option when asked to
dispatch(args=None, scriptname=None)

Dispatch command line arguments using subcommands.

  • args: list of arguments, default: sys.argv[1:]

Project Versions

Table Of Contents

Previous topic

Overview

Next topic

Opster tests

This Page