{ "info": { "author": "Jeff Hammel", "author_email": "jhammel@mozilla.com", "bugtrack_url": null, "classifiers": [], "description": "CommandParser\n=============\n\nchange objects to OptionParser instances via reflection\n\nOverview\n--------\n\nIt is a common pattern for command line interfaces to use subcomands (e.g.):\n\n hg commit -m 'foo bar'\n git push origin master\n\nCommandParser does this via introspection of a given class. When\ninvoked with a class, CommandParser uses the inspect module to pull\nout the mandatory and optional arguments for each of the class's\nmethods, which are translated to subcommands, and make a OptionParser\ninstance from them. ``%prog help`` will then display all of the\nsubcommands and ``%prog help `` will give you help on the\n```` chosen. Methods beginning with an underscore (`_`)\nare passed over. This gives an easy way to translate an API class\ninto a command line program::\n\n class Foo(object):\n \"\"\"silly class that does nothing\"\"\"\n def __init__(self): pass\n def foo(self, value):\n print \"The value is %s\" % value\n def bar(self, fleem, verbose=False):\n \"\"\"\n The good ole `bar` command\n - fleem: you know, that thing fleem\n - verbose: whether to print out more things or not\n \"\"\"\n if verbose:\n print \"You gave fleem=%s\" % fleem\n return fleem * 2\n\n import commandparser\n parser = commandparser.CommandParser(Foo)\n parser.invoke()\n\n(From http://k0s.org/hg/CommandParser/file/tip/tests/simpleexample.py )\n\nExample invocation::\n\n (paint)\u2502./simpleexample.py help\n Usage: simpleexample.py [options] command [command-options]\n \n silly class that does nothing\n \n Options:\n -h, --help show this help message and exit\n \n Commands: \n bar The good ole `bar` command\n foo \n help print help for a given command\n (paint)\u2502./simpleexample.py foo\n Usage: simpleexample.py foo \n \n simpleexample.py: error: Not enough arguments given\n (paint)\u2502./simpleexample.py foo 4\n The value is 4\n (paint)\u2502./simpleexample.py bar blah\n blahblah\n\nFor optional arguments, the type of the default value will be\ninspected from the function signature. Currently, mandatory arguments\nare all strings, though this is clearly a shortcoming.\n\nThe class docstring is used for ``%prog --help`` (and ``%prog help``,\nsame thing). The method docstrings (including those of ``__init__``\nfor global options) are used for subcommand help. If the arguments\nare listed in the docstring in the form given above\n(``- :