Skip to content
TylerTemp edited this page Apr 7, 2016 · 5 revisions

In contrast with argparse, docpie can

  1. reduce the code, in all the following updating you only need to modify your help message
  2. greatly reduce the learning curve, what you see is what you get

In contrast with docopt, docpie can

  1. some BUGs in docopt do not exist in docpie: #71 >>, #282 >>, #130 >>, #275 >>, #209 >>

  2. 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]

  3. 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'}

  4. 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'))

    oneline demo >>

  5. pickle & JSONlize Docpie instance

  6. define and customize the automatically handled option-s

  7. More flexible format in "Options" section

    Usage: prog [options]
    
    Options:
        -r...               repeatable options
        --input=<files>...  repeatable values
        --output[=<file>]   optional value
    

Note

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, while docpie parse lines which starts with - as options. Which means

    Usage: 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 all argv, which means the argv[0] is usually the executed file name, however, docopt accepts argv[1:] as its argv argument

    """Usage: prog cmd"""
    from docopt import docopt
    from docpie import docpie
    print(docopt(__doc__, ['cmd']))
    print(docpie(__doc__, ['my_script.py', 'cmd']))
Clone this wiki locally