Optik 1.4.1 =========== Optik is a powerful, flexible, extensible, easy-to-use command-line parsing library for Python. Using Optik, you can add intelligent, sophisticated handling of command-line options to your scripts with very little overhead. Here's an example of using Optik to add some command-line options to a simple script: from optik import OptionParser [...] parser = OptionParser() parser.add_option("-f", "--file", action="store", type="string", dest="filename", help="write report to FILE", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=1, help="don't print status messages to stdout") (options, args) = parser.parse_args() With these few lines of code, users of your script can now do the "usual thing" on the command-line: <yourscript> -f outfile --quiet <yourscript> -qfoutfile <yourscript> --file=outfile -q <yourscript> --quiet --file outfile (All of these result in options.filename == "outfile" options.verbose == 0 ...just as you might expect.) Even niftier, users can run one of <yourscript> -h <yourscript> --help and Optik will print out a brief summary of your script's optons: usage: <yourscript> [options] options: -h, --help show this help message and exit -fFILE, --file=FILE write report to FILE -q, --quiet don't print status messages to stdout That's just a taste of the flexibility Optik gives you in parsing your command-line. See the documentation included in the package for details. AUTHOR, COPYRIGHT, AVAILABILITY ------------------------------- Optik was written by Greg Ward <gward@python.net> The latest version of Optik can be found at http://optik.sourceforge.net/ Copyright (c) 2001-2003 Gregory P. Ward. All rights reserved. CHANGES IN OPTIK 1.4 -------------------- * Changed to use the new textwrap module included with Python 2.3. Includes a copy of textwrap.py for use with older Python versions. * Set __all__ in each of the optik.* modules, to make life easier for optik/__init__.py. * Rewrote the test suite to use PyUnit, and added some new tests that revealed some long-hidden bugs. Fixed those bugs. (Thanks to Johannes Gijsbers for doing all the work!) * For versions of Python with builtin True and False values (ie. Python 2.2.1 and later), make store_true/store_false use them. * Add forwards-compatibility 'optparse' module, so scripts can import from 'optparse' and work under base Python 2.3, or under older Pythons with Optik 1.4.1 or later installed. -- Greg Ward <gward@python.net> http://www.gerg.ca/ Rules for Urban Cycling, #1: Green means go; yellow means go like hell; red means proceed with caution.
participants (1)
-
Greg Ward