-
Notifications
You must be signed in to change notification settings - Fork 1
Why docpie
In contrast with argparse
, docpie
can
- reduce the code, in all the following updating you only need to modify your help message
- greatly reduce the learning curve, what you see is what you get
In contrast with docopt
, docpie
can
-
some BUGs in
docopt
do not exist indocpie
: #71 >>, #282 >>, #130 >>, #275 >>, #209 >> -
support
cp
style command line''' Usage: mycopy.py <source_file>... <target_directory>; ''' from docpie import docpie from docopt import docopt print('---- docopt ----') try: print(docopt(__doc__)) except BaseException as e: print(e) print('---- docpie ----') try: print(docpie(__doc__)) except BaseException as e: print(e)
output:
$ python mycopy.py ./docpie/*.py ./docpie/test/*.py ~/my_project ---- docopt ---- Usage: mycopy.py <source_file>... <target_directory> ---- docpie ---- {'--': False, '<source_file>': ['./docpie/setup.py', './docpie/test/*.py'], '<target_directory>': '/Users/tyler/my_project'}
[oneline demo >>][mycopy_py]
-
automatically deal
--
command, you don't need to write it again in your help message."""Usage: prog <hello>""" from docpie import docpie print(docpie(__doc__))
[oneline demo >>][helloworld]
When inputting
-- --world
it will return{'--': True, '<hello>': '--world'}
-
specific program's name
""" Usage: myscript.py config $ python myscript.py make $ sudo python myscript.py make install """ from docpie import docpie print(docpie(__doc__, name='myscript.py'))
-
pickle
& JSONlizeDocpie
instance -
define and customize the automatically handled
option
-s -
More flexible format in "Options" section
Usage: prog [options] Options: -r... repeatable options --input=<files>... repeatable values --output[=<file>] optional value
However, docopt
is light-weight and has been tested by many users.
If you've already used docopt
, here is a quick look of differences
between docpie
with docopt
besides what's been mentioned above.
-
docpie
is indent sensitive, whiledocpie
parse lines which starts with-
as options. Which meansUsage: prog [options] Options: -h print this message # works on `docpie` and `docopt` --verbose print more message while running. It's the oppose of --quiet # works on `docpie` but not `docopt`, # because it starts with `-` and `docopt` will parse # it as `--quite` option
-
the
argv
argument receive allargv
, which means theargv[0]
is usually the executed file name, however,docopt
acceptsargv[1:]
as itsargv
argument"""Usage: prog cmd""" from docopt import docopt from docpie import docpie print(docopt(__doc__, ['cmd'])) print(docpie(__doc__, ['my_script.py', 'cmd']))