[getopt-sig] Recent changes in Optik

Greg Ward gward@python.net
Sun, 17 Feb 2002 19:01:00 -0500


Hi all --

based on some of the feedback and requests seen in the past week, I've
made some minor changes to Optik that, I think, will make it even easier
to use.

The most visible is that you can now get away without supplying a type
or a destination for many options.  If you don't supply a type and one
is needed, Optik uses "string"; if you don't supply a destination and
one is needed, Optik extracts a destination from your first long option,
or your first short option if none is supplied.

For example, the following is now valid:

  parser = OptionParser()
  parser.add_option("-f", "--file")

This defines an option whose action is to store a value of type string
in a variable 'file'.  (Well, really, in an instance attribute 'file' of
the Values instance that is created and returned by
parser.parse_args()).  Thus, for the most common kind of option -- the
kind that takes a single string and stores it somewhere, where later
occurences of the option override earlier occurences -- you don't *need*
to specify any keyword args at all.  (You should still supply a help
string, but it's not required.)

If you're really lazy -- or writing a really a quick hack -- you can
get away with

  parser.add_option("-a")

which stores a single string value to the variable 'a'.

The downside of this is that it enables programmers to be implicit
rather than explicit, and we all know that explicit is better than
implicit.  Personally, I will probably take advantage of the default
type a lot, but not the default destination.  YMMV.

Also, I've done some refactoring of the Option and OptionParser classes
that will make extending Optik (in certain directions) easier.  More on
that later.

This is all available by CVS only right now.  There might be an Optik
1.2.1 release soon.  If you're actively using Optik right now, you
should probably check out the CVS code and make sure I haven't screwed
anything up!  (Yes, I have tested all these changes, so you should be
fine.  If you have been subclassing Option and/or OptionParser in weird
ways, though, you might feel some pain.)  Go to optik.sourceforge.net
and follow the links...

        Greg
-- 
Greg Ward - Unix weenie                                 gward@python.net
http://starship.python.net/~gward/
I just read that 50% of the population has below median IQ!