cp

clip.py

Embeddable, composable [c]ommand [l]ine [i]nterface [p]arsing

Showing:

Popularity

Downloads/wk

0

GitHub Stars

193

Maintenance

Last Commit

6yrs ago

Contributors

4

Package

Dependencies

0

License

MIT

Categories

Readme

clip.py


Travis docs license

Embeddable, composable command line interface parsing

Installing

clip is just a pip install clip.py away.

Basic Example

This example is just to whet your appetite. For a more in-depth guide to using clip, please see the docs.

import clip

app = clip.App()

@app.main(description='A very unhelpful shopping list CLI program')
def shopping():
    pass

@shopping.subcommand(description='Add an item to the list')
@clip.arg('item', required=True)
@clip.opt('-q', '--quantity', default=1, help='How many of the item to get')
def add(item, quantity):
    clip.echo('Added "{} - {}" to the list'.format(item, quantity))

@shopping.subcommand(description='See all items on the list')
@clip.flag('--sorted', help='View items in alphabetical order')
def view(sorted):
    clip.echo('This is your {}sorted list'.format('' if sorted else 'un'))

if __name__ == '__main__':
    try:
        app.run()
    except clip.ClipExit:
        pass

If you save the above code in a file called shopping.py, you can then do the following:

$ python shopping.py -h
shopping: A very unhelpful shopping list CLI program

Usage: shopping {{options}} {{subcommand}}

Options:
  -h, --help  Show this help message and exit

Subcommands:
  add   Add an item to the list
  view  See all items on the list
$ python shopping.py add -h
shopping add: Add an item to the list

Usage: add {{arguments}} {{options}}

Arguments:
  item [text]  

Options:
  -h, --help            Show this help message and exit
  -q, --quantity [int]  How many of the item to get (default: 1)
$ python shopping.py add
Error: Missing parameter "item".
$ python shopping.py add cookies -q 10
Added "cookies - 10" to the list
$ python shopping.py view
This is your unsorted list
$ python shopping.py view --sorted
This is your sorted list

Testing

Call tests with python setup.py test.

Credits

  • Aaargh: Some parsing logic
  • Click: Decorator systems, parameter features
  • docopt: Help text formatting

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100