author | Alexander Solovyov <piranha@piranha.org.ua> |
Mon, 13 Jul 2009 18:23:42 +0300 (2009-07-13) | |
changeset 33 | e82b3f5c36d9 |
parent 28 | 1a90a706e10d |
child 34 | e4588c625dcb |
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 |
|
33 | 7 |
:: |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
8 |
|
33 | 9 |
If that's the Final Option, |
10 |
I'm gonna choose it. |
|
11 |
Die Krupps |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
12 |
|
33 | 13 |
Finaloption is a command line parser, indented to make writing command line |
14 |
applications easy and painless. It uses built-in Python types (lists, |
|
15 |
dictionaries, etc) to define options, which makes configuration clear and |
|
16 |
concise. Additionally it contains possibility to handle subcommands (i.e. |
|
17 |
``hg commit`` or ``svn update``). |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
18 |
|
33 | 19 |
JFYI: name is derived from Die Krupps' song Final Option, featured in epigraph. |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
20 |
|
33 | 21 |
Quick example |
22 |
------------- |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
23 |
|
33 | 24 |
That's simple example to show you example of an option definition:: |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
25 |
|
33 | 26 |
import sys |
27 |
from finaloption import command |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
28 |
|
33 | 29 |
@command(usage='%name [-n] MESSAGE') |
30 |
def main(message, |
|
31 |
nonewline=('n', False, 'don\'t print a newline')): |
|
32 |
'Simple echo program' |
|
33 |
sys.stdout.write(message) |
|
34 |
if not nonewline: |
|
35 |
sys.stdout.write('\n') |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
36 |
|
33 | 37 |
if __name__ == '__main__': |
38 |
main() |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
39 |
|
33 | 40 |
Running this program will print the help:: |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
41 |
|
33 | 42 |
echo.py [-n] MESSAGE |
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
43 |
|
33 | 44 |
Simple echo program |
45 |
||
46 |
options: |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
47 |
|
33 | 48 |
-n --nonewline don't print a newline |
49 |
-h --help show help |
|
22
8e56f2a8b90a
initial version of readme
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff
changeset
|
50 |
|
33 | 51 |
I think this mostly describes what's going to. To learn more, read documentation. |