Package logilab :: Package common :: Module clcommands :: Class CommandLine

[frames] | no frames]

# Class CommandLine

source code

    object --+
             |
          dict --+
                 |
                CommandLine

    Usage:

    >>> LDI = cli.CommandLine('ldi', doc='Logilab debian installer',
                              version=version, rcfile=RCFILE)
    >>> LDI.register(MyCommandClass)
    >>> LDI.register(MyOtherCommandClass)
    >>> LDI.run(sys.argv[1:])

    Arguments:

    * `pgm`, the program name, default to `basename(sys.argv[0])`

    * `doc`, a short description of the command line tool

    * `copyright`, additional doc string that will be appended to the generated
      doc

    * `version`, version number of string of the tool. If specified, global
      --version option will be available.

    * `rcfile`, path to a configuration file. If specified, global --C/--rc-file
      option will be available?  self.rcfile = rcfile

    * `logger`, logger to propagate to commands, default to
      `logging.getLogger(self.pgm))`

Instance Methods

    new empty dictionary

__init__(self, pgm=None, doc=None, copyright=None, version=None, rcfile=None, logthreshold=logging.ERROR, check_duplicated_command=True) x.__init__(...) initializes x; see help(type(x)) for signature | source code

register(self, cls, force=False) register the given :class:`Command` subclass | source code

run(self, args) main command line access point: * init logging * handle global options (-h/--help, --version, -C/--rc-file) * check command * run command | source code

create_logger(self, handler, logthreshold=None) | source code

get_command(self, cmd, logger=None) | source code

usage(self) display usage for the main program (i.e. | source code

usage_and_exit(self, status) | source code

Inherited from `dict`: `__cmp__`, `__contains__`, `__delitem__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__gt__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__repr__`, `__setitem__`, `__sizeof__`, `clear`, `copy`, `fromkeys`, `get`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `pop`, `popitem`, `setdefault`, `update`, `values`, `viewitems`, `viewkeys`, `viewvalues`

Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`, `__subclasshook__`

Class Variables
Inherited from `dict`: `__hash__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, pgm=None, doc=None, copyright=None, version=None, rcfile=None, logthreshold=logging.ERROR, check_duplicated_command=True)
(Constructor)

source code

x.__init__(...) initializes x; see help(type(x)) for signature

Returns:

    new empty dictionary

Overrides: object.__init__
  (inherited documentation)

### run(self, args)

source code

    main command line access point:
    * init logging
    * handle global options (-h/--help, --version, -C/--rc-file)
    * check command
    * run command

    Terminate by :exc:`SystemExit`

### usage(self)

source code

    display usage for the main program (i.e. when no command supplied)
    and exit