python cli scripts for humans
Project description
Easy python cli scripts for people that just want get things done.
Captain was lovingly crafted for First Opinion.
Usage
A valid captain cli script needs two things:
a shebang on the first line
#!/usr/bin/env python
a main function
def main(foo, bar): return 0
That’s it! Whatever arguments you define in the main function will be options on the command line.
def main(foo, bar):
return 0
can be called on the command line:
$ pyc path/to/script.py --foo=1 --bar=2
Examples
A typical standard python cli script:
import argparse
if __name__ == u'__main__':
parser = argparse.ArgumentParser(description='fancy script description')
parser.add_argument("--foo", action='store_true')
parser.add_argument("--bar", default=0, type=int)
parser.add_argument("args", nargs='*')
args = parser.parse_args()
would become:
#!/usr/bin/env python
def main(foo=False, bar=0, *args):
'''fancy script description'''
return 0
You can get a list of all available scripts in a directory by running captain with no arguments:
$ captain
Install
Use pip:
$ pip install captain
License
MIT
TODO
allow you to set *_arg values, so you could do arg=[int] to make sure the *args values where all ints, likewise, you could do foo_arg, bar_arg and that would be positional arg 0 and 1, I think this would work ok and be ok, we could also make everything that ends in _kwarg be a named argument and everything that ends in _arg be a positional argument. Then *args and **kwargs would just be for everything else (the catchall).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.