Skip to content

Commit a3d8ae0

Browse files
committed
readme
1 parent b77123a commit a3d8ae0

File tree

2 files changed

+87
-11
lines changed

2 files changed

+87
-11
lines changed

README.md

+72-11
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,97 @@
1-
argscript
2-
=========
1+
[argscript][] is a port of [werkzeug.script][ws] to [argparse][]. Argscript generates
2+
a an argparse command line parser from the function definitions of a script.
3+
4+
> An action is a function in the same module starting with `action_` which takes
5+
a number of arguments where every argument has a default. The type of the
6+
default value specifies the type of the argument. Arguments can then be passed by using `--name=value` from the shell. [werkzeug.script][ws]
37

4-
Port of [werkzeug.script][ws] to [argparse][].
58

6-
Since werkzeug.script is being deprecated, I've ported it to argparse.
79

810
Basic Usage is the same as werkzeug.script:
911

1012
#!/usr/bin/env python
1113
# -*- coding: utf-8 -*-
12-
"""Docstring for script"""
14+
"""Docstring for test script"""
1315

1416
import argscript
1517

1618
# actions go here
17-
def action_foo(arg='test'):
19+
def action_foo(arg1='test'):
1820
"""doc for action foo
1921
20-
arg -- first argument
22+
arg1 -- first argument
2123
"""
22-
pass
24+
print 'action_foo called with argument arg1: %s' % arg1
2325

24-
def action_lee(bar=4):
26+
def action_bar(msg='', times=1):
2527
"""doc for action bar
2628

27-
bar -- run with bar
29+
msg -- a message
30+
times -- number
2831
"""
29-
pass
32+
print 'action_lee called with arguments msg: %s, times: %s' %(msg, times)
33+
3034

3135
if __name__ == '__main__':
3236
argscript.run()
3337

38+
Now you can run the script with the `-h` parameter to show a basic help. The
39+
docstring from the `test.py` script is reused in the help message.
40+
41+
$ ./test.py -h
42+
usage: test.py [-h] {foo,bar} ...
43+
44+
Docstring for test script
45+
46+
positional arguments:
47+
{foo,bar}
48+
49+
optional arguments:
50+
-h, --help show this help message and exit
51+
52+
To get the help message for a particular action call the script with the action
53+
name and the `-h` parameter:
54+
55+
$ ./test.py bar -h
56+
usage: test.py bar [-h] [--msg MSG] [--times TIMES]
57+
58+
doc for action bar
59+
60+
optional arguments:
61+
-h, --help show this help message and exit
62+
--msg MSG a message
63+
--times TIMES number
64+
65+
Again the function docstring is reuesed in the help message. If you specify
66+
a description for the arguments in the doc string (`variable -- doc`), they are
67+
reuesed too.
68+
69+
Now you can run the script with the action name and the parameters, and the
70+
action function will be called with them. If you obmit a parameter, the default
71+
value will be used to call the function.
72+
73+
$ ./test.py bar --msg='Hello World' --times=4
74+
75+
action_lee called with arguments msg: Hello World, times: 4
76+
77+
78+
## Installation
79+
80+
You can either install the development version from [github][argscript]:
81+
82+
git clone [email protected]:hoffmann/argscript.git
83+
cd argscript
84+
sudo python setup.py install
85+
86+
87+
or install it from [pypi.python.org][pypi]:
88+
89+
pip install argscript
90+
91+
92+
3493

3594
[ws]: http://werkzeug.pocoo.org/docs/script/
3695
[argparse]: http://docs.python.org/library/argparse.html
96+
[argscript]: https://github.com/hoffmann/argscript
97+
[pypi]: http://pypi.python.org/pypi/argscript/

setup.py

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
of the default value specifies the type of the argument. Arguments can
1111
then be passed by using `--name=value` from the shell. [werkzeug.script]
1212
13+
Installation
14+
------------
15+
16+
**development version:**::
17+
18+
git clone [email protected]:hoffmann/argscript.git
19+
cd argscript
20+
sudo python setup.py install
21+
22+
23+
**from pypi.python.org:**::
24+
25+
pip install argscript
26+
27+
1328
"""
1429

1530
from distutils.core import setup

0 commit comments

Comments
 (0)