README
author Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
Sat, 11 Sep 2010 15:16:24 +0400 (2010-09-11)
changeset 119 f9c027029540
parent 75 2782b2406ba8
child 123 4d73a8af4bbf
permissions -rw-r--r--
Fixed catching unnececcary exceptions Exception Abort can't be thrown, so it is useless. Catching SystemExit and KeyboardInterrupt makes little sense as the thread can be terminated by KeyboardInterrupt before or after entering the wrapped command processing function. So one have to handle these exceptions in his main function anyway. Catching any exception in order to print a message and re-raise it changes the standard behaviour and might seem confusing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     1
.. -*- mode: rst -*-
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     2
75
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
     3
========
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
     4
 Opster
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
     5
========
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     6
75
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
     7
Opster is a command line parser, intended to make writing command line
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
     8
applications easy and painless. It uses built-in Python types (lists,
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
     9
dictionaries, etc) to define options, which makes configuration clear and
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    10
concise. Additionally it contains possibility to handle subcommands (i.e.
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    11
``hg commit`` or ``svn update``).
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    12
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    13
Quick example
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    14
-------------
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    15
68
36ce7dcfe7c0 readme fix
Alexander Solovyov <piranha@piranha.org.ua>
parents: 53
diff changeset
    16
That's an example of an option definition::
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    17
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    18
  import sys
75
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
    19
  from opster import command
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    20
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    21
  @command(usage='%name [-n] MESSAGE')
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    22
  def main(message,
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    23
           nonewline=('n', False, 'don\'t print a newline')):
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    24
      'Simple echo program'
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    25
      sys.stdout.write(message)
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    26
      if not nonewline:
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    27
          sys.stdout.write('\n')
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    28
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    29
  if __name__ == '__main__':
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    30
      main()
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    31
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    32
Running this program will print the help::
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    33
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    34
  echo.py [-n] MESSAGE
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    35
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    36
  Simple echo program
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    37
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    38
  options:
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    39
33
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    40
   -n --nonewline  don't print a newline
e82b3f5c36d9 documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 28
diff changeset
    41
   -h --help       show help
22
8e56f2a8b90a initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    42
49
a3feac00d151 small documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 41
diff changeset
    43
I think this mostly describes what's going on, except that I'd like to mention
a3feac00d151 small documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents: 41
diff changeset
    44
one interesting feature - if you are using long name for option, you can use
53
1d0173e1b412 version bump and minor documentation fixes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 49
diff changeset
    45
only partial name, for example ``./echo.py --nonew`` a is valid command
1d0173e1b412 version bump and minor documentation fixes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 49
diff changeset
    46
line. This is also true for subcommands: read about that and everything else
1d0173e1b412 version bump and minor documentation fixes
Alexander Solovyov <piranha@piranha.org.ua>
parents: 49
diff changeset
    47
you'd like to know in `documentation`_.
34
e4588c625dcb readme: link to documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents: 33
diff changeset
    48
75
2782b2406ba8 rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents: 68
diff changeset
    49
.. _documentation: http://hg.piranha.org.ua/opster/docs/