author | Alexander Solovyov <alexander@solovyov.net> |
Wed, 26 Jan 2011 19:01:37 +0100 (2011-01-26) | |
changeset 172 | f495e252c498 |
parent 145 | 6dc40423b257 |
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 |
|
123
4d73a8af4bbf
locale troubles fixed, test suite moved to cram
Alexander Solovyov <piranha@piranha.org.ua>
parents:
75
diff
changeset
|
7 |
Opster is a command line options 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, |
|
134 | 23 |
no_newline=('n', False, 'don\'t print a newline')): |
33 | 24 |
'Simple echo program' |
25 |
sys.stdout.write(message) |
|
134 | 26 |
if not no_newline: |
33 | 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 |
|
134 | 40 |
-n --no-newline 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 |
|
134 | 43 |
As you can see, here we have defined option to not print newline: keyword |
44 |
argument name is a long name for option, default value is a 3-tuple, containing |
|
45 |
short name for an option (can be empty), default value (on base of which |
|
46 |
processing is applied - `see description`_) and a help string. |
|
47 |
||
48 |
Underscores in long names are converted into dashes. |
|
49 |
||
50 |
If you are calling a command with option using long name, you can supply it |
|
51 |
partially. In this case it could look like ``./echo.py --nonew``. This is also |
|
52 |
true for subcommands: read about them and everything else you'd like to know in |
|
53 |
`documentation`_. |
|
34
e4588c625dcb
readme: link to documentation
Alexander Solovyov <piranha@piranha.org.ua>
parents:
33
diff
changeset
|
54 |
|
75
2782b2406ba8
rename from finaloption to opster
Alexander Solovyov <piranha@piranha.org.ua>
parents:
68
diff
changeset
|
55 |
.. _documentation: http://hg.piranha.org.ua/opster/docs/ |
135
444518c54a66
small docs update
Alexander Solovyov <alexander@solovyov.net>
parents:
134
diff
changeset
|
56 |
.. _see description: http://hg.piranha.org.ua/opster/docs/overview.html#options-processing |
145
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
57 |
|
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
58 |
Plans |
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
59 |
----- |
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
60 |
|
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
61 |
- Better documentation |
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
62 |
- (under consideration) ability to have few command collectors in a single |
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
63 |
application (more than one dispatching entry point) |
6dc40423b257
that's 1.0, why not after all? :)
Alexander Solovyov <alexander@solovyov.net>
parents:
135
diff
changeset
|
64 |