File: README.rst

package info (click to toggle)
python-opster 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 104 kB
  • sloc: python: 707; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,802 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
.. -*- mode: rst -*-

========
 Opster
========

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``).


.. note:: Requires at least Python 2.6


Quick example
-------------

That's an example of an option definition::

  import sys
  from opster import command

  @command()
  def main(message,
           no_newline=('n', False, "don't print a newline")):
      '''Simple echo program'''
      sys.stdout.write(message)
      if not no_newline:
          sys.stdout.write('\n')

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

Running this program will print help message::

  > ./echo.py
  echo.py: invalid arguments
  echo.py [OPTIONS] MESSAGE

  Simple echo program

  options:

   -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 of options 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 ``./echo.py --no-new``. This is also
true for subcommands: read about them and everything else you'd like to know in
`documentation`_.

.. _documentation: http://opster.readthedocs.org/en/latest/
.. _see description: http://opster.readthedocs.org/en/latest/overview.html#options-processing