author | Alexander Solovyov <piranha@piranha.org.ua> |
Wed, 19 Aug 2009 12:35:31 +0300 (2009-08-19) | |
changeset 77 | 2f1dfda4cfb3 |
parent 75 | 2782b2406ba8 |
child 123 | 4d73a8af4bbf |
permissions | -rw-r--r-- |
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 | 8 |
applications easy and painless. It uses built-in Python types (lists, |
9 |
dictionaries, etc) to define options, which makes configuration clear and |
|
10 |
concise. Additionally it contains possibility to handle subcommands (i.e. |
|
11 |
``hg commit`` or ``svn update``). |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
12 |
|
33 | 13 |
Quick example |
14 |
------------- |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
15 |
|
68 | 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 | 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 | 21 |
@command(usage='%name [-n] MESSAGE') |
22 |
def main(message, |
|
23 |
nonewline=('n', False, 'don\'t print a newline')): |
|
24 |
'Simple echo program' |
|
25 |
sys.stdout.write(message) |
|
26 |
if not nonewline: |
|
27 |
sys.stdout.write('\n') |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
28 |
|
33 | 29 |
if __name__ == '__main__': |
30 |
main() |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
31 |
|
33 | 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 | 34 |
echo.py [-n] MESSAGE |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
35 |
|
33 | 36 |
Simple echo program |
37 |
||
38 |
options: |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
39 |
|
33 | 40 |
-n --nonewline don't print a newline |
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/ |