[Python-Dev] Proposed standard module: Optik

Greg Ward gward@python.net
Mon, 11 Feb 2002 11:10:25 -0500

On 11 February 2002, Guido van Rossum said:
> No immediate objection, although there are some other fancy options
> packages around, and IMO you have to explain why Optik is better.

Well, here's what I like about Optik:

  * it ties short options and long options together, so once you
    define your options you never have to worry about the fact that
    -f and --file are the same

  * it's strongly typed: if you say option --foo expects an int,
    then Optik makes sure the user supplied a string that can be
    int()'ified, and supplies that int to you

  * it automatically generates full help based on snippets of
    help text you supply with each option

  * it has a wide range of "actions" -- ie. what to do with the
    value supplied with each option.  Eg. you can store that value
    in a variable, append it to a list, pass it to an arbitrary
    callback function, etc.

  * you can add new types and actions by subclassing -- how to
    do this is documented and tested

  * it's dead easy to implement simple, straightforward, GNU/POSIX-
    style command-line options, but using callbacks you can be as
    insanely flexible as you like

  * provides lots of mechanism and only a tiny bit of policy (namely,
    the --help and (optionally) --version options -- and you can
    trash that convention if you're determined to be anti-social)

Anyways, read the docs at optik.sourceforge.net for the whole deal.

> Can we change the name?  Optik is nice for a standalone 3rd party
> module/package but a bit too fancyful for a standard library module.

Sure, no problem.

> It could be a new function in getopt:
>     from getopt import OptionParser
>     [...]
>     parser = OptionParser()

I guess that's OK if we're agreed that Optik is the be-all, end-all
option-parsing tool.  (I happen to think so, but I'd like to get
opinions from a few other python-dev'ers before I let this go to my
head.)  I'm pretty cool to names like "super_getopt" or "fancy_getopt",
despite having perpetrated precisely the latter in the Distutils.  ;-(

Greg Ward - geek-at-large                               gward@python.net
Know thyself.  If you need help, call the CIA.