Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Command line parsing speedster

Fetching latest commit…

Cannot retrieve the latest commit at this time

.. -*- mode: rst -*-


Opster is a command line options parser, intended to make writing command line
applications easy and painless. It uses built-in Python types (lists,
dictionaries, etc) to define options, which makes configuration clear and
concise. Additionally it contains possibility to handle subcommands (i.e.
``hg commit`` or ``svn update``).

Quick example

That's an example of an option definition::

  import sys
  from opster import command

  @command(usage='%name [-n] MESSAGE')
  def main(message,
           no_newline=('n', False, 'don\'t print a newline')):
      'Simple echo program'
      if not no_newline:

  if __name__ == '__main__':

Running this program will print the help:: [-n] MESSAGE

  Simple echo program


   -n --no-newline  don't print a newline
   -h --help        show help

As you can see, here we have defined option to not print newline: keyword
argument name is a long name for option, default value is a 3-tuple, containing
short name for an option (can be empty), default value (on base of which
processing is applied - `see description`_) and a help string.

Underscores in long names are converted into dashes.

If you are calling a command with option using long name, you can supply it
partially. In this case it could look like ``./ --nonew``. This is also
true for subcommands: read about them and everything else you'd like to know in

.. _documentation:
.. _see description:


 - Better documentation
 - (under consideration) ability to have few command collectors in a single
   application (more than one dispatching entry point)

Something went wrong with that request. Please try again.