[getopt-sig] Recent changes in Optik
Greg Ward
gward@python.net
Mon, 18 Feb 2002 21:43:57 -0500
On 17 February 2002, I said:
> 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.
Oh yeah, I forgot to mention the other changes I've been making.
Specifically, I've added an "examples" directory to the Optik CVS (will
be included in the next release) where I can play around with
implementing those features that people request but that I don't want to
add to Optik proper. This forces me to actually test that Optik is
really as easily as extensible as I claim it is, and gives everyone else
canonical implementations of those heretical features.
So far, I've implemented a case-insensitive option parser and two
variations on "required options". Surprise surprise, each new example
has resulted in minor tweaks to Optik -- specifically the OptionParser
constructor -- to make it easier to extend. For example, with the code
currently in CVS, a case-insensitive option parser is pretty easy:
class CaselessOptionParser (OptionParser):
def _create_option_list (self):
self.option_list = []
self._short_opt = caseless_dict()
self._long_opt = caseless_dict()
self._long_opts = []
self.defaults = {}
def _match_long_opt (self, opt):
return _match_abbrev(opt.lower(), self._long_opt.keys())
(The implementation of caseless_dict is left as an exercise to the
reader. Or check out the current Optik CVS and see
examples/caseless.py.)
I invite everyone to take a check out the current Optik CVS and poke
around the examples directory. If nothing else, this will serve as a
place to send people who ask for features that I don't think belong in
Optik proper.
Greg
--
Greg Ward - Unix nerd gward@python.net
http://starship.python.net/~gward/
"Question authority!" "Oh yeah? Says who?"