Perceived optparse shortcomings

Heather Coppersmith me at privacy.net
Wed Mar 17 14:39:58 CET 2004


On 16 Mar 2004 23:20:10 -0800,
hjwidmaier at web.de (Hans-Joachim Widmaier) wrote:

> With this program I'm working on, I started to recognize that
> not only the functionality should be delegated to modules, but
> that most command line options are private to these modules
> (call 'em plug-ins) as well. This calls for a command line like
> CVS or subverion employ:

> <cmd> <generic options> <subcmd> <subcmd options> <args>

> There are several ways to do it:

[ snip ]

How about having your plugins "register" with your main program
*before* you call optparse?  Part of the registration would be
something like "I (the plugin) accespt these options with/without
these arguments, and here are some callbacks to handle them."
During registration, build up the argument strings/arrays/etc. you
need for optparse from that information.

I've not used optparse, but I've used that scheme with getopt.

If you allow interspersed options, you (your main program) will
have to handle conflicts gracefully (i.e., plugin1 and plugin2
both want an "-a" option).

Regards,
Heather

-- 
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli



More information about the Python-list mailing list