ANNOUNCE: Optik 1.4 released
Greg Ward
gward@python.net
Sat, 12 Oct 2002 21:17:59 -0400
Optik 1.4
=========
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 Gregory P. Ward. All rights reserved.
CHANGES IN OPTIK 1.4
--------------------
[editorial note: most significant code changes in Optik 1.4 were
made by David Goodger; except as noted below, David should be credited
with everything in this list! I just rearranged some of his changes,
renamed a few thing, and put out the release. --Greg]
* Factored the help-formatting code out of OptionParser into
some new classes (HelpFormatter and subclasses) in help.py. This
should make it a lot easier to customize how help is formatted.
* Added the notion of "option groups": an OptionParser can now
contain several option groups, each which contains several options.
The main purpose of this is to enable sensibly-grouped help output,
but it opens up all sorts of interesting (and largely untested)
possibilities for code to throw whole option groups around instead
of individual options. Added two new classes: OptionGroup, and
OptionContainer for code common to OptionParser and OptionGroup.
(OptionContainer should be invisible to programmers using Optik).
* Added the 'description' attribute and set_description() method to
both OptionParser and OptionGroup (actually OptionContainer, but
I just said that class was invisible). Again, this is to make
help output more useful.
* Made it easier for OptionParser subclasses to decide whether
they should have the standard "help" option, by moving the logic
from class level to the _populate_option_list() method.
* Added the "choice" option type, which is just a string type
constrained to a fixed set of values.
* Added method get_default_values() to OptionParser.
* Rewrote how OptionParser recognizes abbreviated long
options; removed a redundant internal instance attribute.
* Simplify parsing logic in OptionParser a tad by relocating a loop
and renaming _process_arg() to _process_args().
--
Greg Ward <gward@python.net> http://www.gerg.ca/
Jesus Saves -- and you can too, by redeeming these valuable coupons!