[Docpie]

Fork me on GitHub

Quick Start


docpie can:

  • read & analyze the help message you defined, and
  • convert the command-line your app received to an dict.

The help message you give to docpie is quite similar to man page with some formalization. Here is a quick example:

"""
Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<km/h>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h -? --help    Show this screen.
  --version       Show version.
  --speed=<km/h>  Speed in knots.[default: 10]
  --moored        Moored (anchored) mine.
  --drifting      Drifting mine.
"""

from docpie import docpie
print(docpie(__doc__))

try it >>

This example defines several usage patterns in "Usage:" section. Each pattern starts with the executable program name naval_fate, followed by some combinations of Command (ship, new, move, etc.), Argument (<name>, <x>, <y>) and Option(--speed=<km/h>, --version, etc.).

Here are also some symbols in "Usage" to indicate the requirement of each element: ( )(parentheses) & [ ](brackets) for required element(s) & optional element(s); | (pipe) for exclusive cases; ...(ellipsis) for repeatable element(s).

Below "Usage" is the "Options" section. The options and descriptions are listed here. "Options" section defines the synonymous(e.g. short options -? & -h are the same as long option --help), the expecting argument(e.g. --speed requires one value) and the default value(e.g. by default --speed values "10") of each option.

docpie will generate a parser according to the message above. When the app receives the command-line, docpie will parse it into an appropriate key-value pair dictionary. docpie will also automaticly print this message when -h/-?/ --help appears in the command-line.


docpie has been tested with Python:

2.6, 2.7

3.2, 3.3, 3.4, 3.5

pypy-2.0, pypy-2.6, pypy3-2.4


If you like this project, you can buy me a beer to help me make it better! | Flattr this

侧栏导航