author | Alexander Solovyov <piranha@piranha.org.ua> |
Fri, 07 Aug 2009 16:47:17 +0300 (2009-08-07) | |
changeset 71 | 78fa11005c83 |
parent 68 | 36ce7dcfe7c0 |
child 75 | 2782b2406ba8 |
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 |
|
33 | 3 |
============= |
4 |
Finaloption |
|
5 |
============= |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
6 |
|
36 | 7 |
Finaloption 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 |
|
41
8f651939cab7
no epigraph in readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
36
diff
changeset
|
13 |
JFYI: name is derived from Die Krupps' song Final Option. |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
14 |
|
33 | 15 |
Quick example |
16 |
------------- |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
17 |
|
68 | 18 |
That's an example of an option definition:: |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
19 |
|
33 | 20 |
import sys |
21 |
from finaloption import command |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
22 |
|
33 | 23 |
@command(usage='%name [-n] MESSAGE') |
24 |
def main(message, |
|
25 |
nonewline=('n', False, 'don\'t print a newline')): |
|
26 |
'Simple echo program' |
|
27 |
sys.stdout.write(message) |
|
28 |
if not nonewline: |
|
29 |
sys.stdout.write('\n') |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
30 |
|
33 | 31 |
if __name__ == '__main__': |
32 |
main() |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
33 |
|
33 | 34 |
Running this program will print the help:: |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
35 |
|
33 | 36 |
echo.py [-n] MESSAGE |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
37 |
|
33 | 38 |
Simple echo program |
39 |
||
40 |
options: |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
41 |
|
33 | 42 |
-n --nonewline don't print a newline |
43 |
-h --help show help |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
44 |
|
49
a3feac00d151
small documentation update
Alexander Solovyov <piranha@piranha.org.ua>
parents:
41
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
you'd like to know in `documentation`_. |
34
e4588c625dcb
readme: link to documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents:
33
diff
changeset
|
50 |
|
e4588c625dcb
readme: link to documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents:
33
diff
changeset
|
51 |
.. _documentation: http://hg.piranha.org.ua/finaloption/docs/ |