If you've ever struggled with argparse--and let's be honest, I know you have--then you might be interested in docopt. docopt is a simpler way to write an argument parser, by not writing the argument parser at all.
$ python boo-argparse.py -h usage: boo-argparse.py [-h] [--sum] N [N ...] Process some integers. positional arguments: N an integer for the accumulator optional arguments: -h, --help show this help message and exit --sum sum the integers (default: find the max)
$ python yay-docopt.py -h usage: yay-docopt.py [--sum] N [N ...] Process some integers. Arguments: N an integer for the accumulator Options: -h, --help show this help message and exit --version show version information --sum sum the integers
boom - a simple CLI key-value store Usage: boom boom get boom add [-f|--force] [] boom delete [-f|--force] boom find Commands: add Adds with value get Displays the value of delete Deletes and its value find Find keys matching Options: -h, --help Print this message --version Print version information -f, --force Don't confirm the action
BOOM.PY """ boom - a simple CLI key-value store Usage: boom boom get boom add [-f|--force] [] boom delete [-f|--force] boom find Commands: add Adds with value get Displays the value of delete Deletes and its value find Find keys matching Options: -h, --help Print this message --version Print version information -f, --force Don't confirm the action """
BOOM.PY """ boom - a simple CLI key-value store Usage: boom boom get boom add [-f|--force] [] boom delete [-f|--force] boom find Commands: add Adds with value get Displays the value of delete Deletes and its value find Find keys matching Options: -h, --help Print this message --version Print version information -f, --force Don't confirm the action """ from docopt import docopt
""" boom - a simple CLI key-value store Usage: boom boom get boom add [-f|--force] [] boom delete [-f|--force] boom find Commands: add Adds with value get Displays the value of delete Deletes and its value find Find keys matching Options: -h, --help Print this message --version Print version information -f, --force Don't confirm the action """ from docopt import docopt if __name__ == '__main__': arguments = docopt(__doc__, version='boom.py 1.0') print(arguments) BOOM.PY
BOOM.PY """ boom - a simple CLI key-value store Usage: boom boom get boom add [-f|--force] [] boom delete [-f|--force] boom find Commands: add Adds with value get Displays the value of delete Deletes and its value find Find keys matching Options: -h, --help Print this message --version Print version information -f, --force Don't confirm the action """ from docopt import docopt if __name__ == '__main__': arguments = docopt(__doc__, version='boom.py 1.0') print(arguments)