Пример #1
0
import json
try:
    import cPickle as pickle
except ImportError:  # py3 maybe
    import pickle
from docpie import Docpie, __version__


def short_help_handler(pie, flag):
    print(pie.usage_text)
    print('')
    print('Use `--help` to see more help message')
    sys.exit()


pie = Docpie(__doc__, version=__version__)
pie.set_auto_handler('-?', short_help_handler)

result = pie.docpie()
print(pie)

if result['dump']:
    path = result['--path']
    assert os.path.isdir(path)
    name = result['--name']
    if name is None:
        name, _ = os.path.splitext(__file__)
        _, name = os.path.split(name)
    file = os.path.join(path, name)
    fmt = result['--format']
    prog [dev-options]

Options:
    -h, --help     print this message
    -v, --version  print version
Dev Options:
    -d, --debug          open debug mode
    -o, --output=<file>  debug output file
"""

from docpie import Docpie
from sys import exit


def help_handler(pie, flag):
    doc = pie.doc
    options = pie.option_sections
    # get the 'Dev Options' section
    dev = options['Dev']
    print(doc.replace(dev, ''))
    exit()


pie = Docpie(__doc__)
pie.set_auto_handler('-h', help_handler)


if __name__ == '__main__':
    pie.docpie()
    print(pie)
Пример #3
0
import os
import json
try:
    import cPickle as pickle
except ImportError:    # py3 maybe
    import pickle
from docpie import Docpie, __version__


def short_help_handler(pie, flag):
    print(pie.usage_text)
    print('')
    print('Use `--help` to see more help message')
    sys.exit()

pie = Docpie(__doc__, version=__version__)
pie.set_auto_handler('-?', short_help_handler)

result = pie.docpie()
print(pie)

if result['dump']:
    path = result['--path']
    assert os.path.isdir(path)
    name = result['--name']
    if name is None:
        name, _ = os.path.splitext(__file__)
        _, name = os.path.split(name)
    file = os.path.join(path, name)
    fmt = result['--format']
Пример #4
0
    write_get_index(title, the_stream)
    write_main(title, len(pie.usages), the_stream)

    for index, usage in enumerate(pie.usages):
        write_usage_method(title, index, usage, the_stream)

    write_end(title, the_stream)

    if stream is None:
        the_stream.seek(0)
        return the_stream.read()


if __name__ == '__main__':
    from docpie import Docpie
    logging.getLogger('docpie').setLevel(logging.CRITICAL)
    doc = """
    Usage: prog [options] cmd <arg1> --force=<sth> [odd even]...
           prog --else
           prog --infinite...

    Options:
        -a, --about
        -s, --sth=<wrong>
        --inf=<inf>
    """

    pie = Docpie(doc)
    result = bash(pie, 'demo')
    print(result)