All Projects → TylerTemp → docpie

TylerTemp / docpie

Licence: MIT license
An easy and Pythonic way to create your POSIX command line

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to docpie

docopt-ng
Humane command line arguments parser. Now with maintenance, typehints, and complete test coverage.
Stars: ✭ 94 (+308.7%)
Mutual labels:  optparse
clingon
Command-line options parser system for Common Lisp
Stars: ✭ 34 (+47.83%)
Mutual labels:  optparse

docpie

An easy and Pythonic way to create your POSIX command line

View on: GitHub / PyPi

https://travis-ci.org/TylerTemp/docpie.svg?branch=master

ChangeLog

version 0.4.3:

  • [change] no more locals under docpie function as it may lead to unexpected behavior

full changelog & TODOs

Summary

How do you define your command line interface? Write a parse by yourself or spend hours learning optparse / argparse , and modify both code side and document every time you update the interface?

Life is short, man! You can simply do it this way:

"""
My copy script

Usage:
  cp.py [options] <source_file> <target_file>
  cp.py [options] <source_file>... <target_directory>

Options:
  -h -? --help    print this screen
  --version       print the version of this script
  -v --verbose    print more information while  running
"""

from docpie import docpie
args = docpie(__doc__)
print(args)

Now run it

$ python cp.py a.txt b.txt c.txt /tmp
{'--': False,
 '--help': False,
 '--verbose': False,
 '--version': False,
 '-?': False,
 '-h': False,
 '-v': False,
 '<source_file>': ['a.txt', 'b.txt', 'c.txt'],
 '<target_directory>': '/tmp',
 '<target_file>': None}

Write a __doc__, pass it to a function, DONE! Isn't it simple?

try it >>

Installation

Install release version:

pip install docpie

Install nightly/dev version:

pip install git+https://github.com/TylerTemp/docpie.git@dev

docpie has been tested with Python:

  • 2.6, 2.7, pypy-2.0, pypy-2.6
  • 3.2, 3.3, 3.4, 3.5, pypy3-2.4

You can run test suit by python setup.py test

Get Start!

Interested? Visit Wiki and get start!

Or you can try it in your browser

Why docpie?

docpie can greatly reduce the work you need to be done for command-line interface. What you see is what you get. Every time you only need to update your document, and keep the code unchanged.

See here for more reasons.

Reference

the code in bashlog.py is taken from tornado, and tracemore.py is from python Cookbook

Many examples & tests are from docopt.

License

docpie is released under MIT-License

Donate

If you like this project, you can buy me a beer so I can make it better!

https://dn-tyler.qbox.me/alipay.ico https://button.flattr.com/flattr-badge-large.png
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].