Re: partial option parsing

Greg Ward <[email protected]> Mon, 25 Nov 2002 12:10:51 -0500
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
On 24 November 2002, Jack Moffitt said:
> I have a program that has many subcommands.  A lot of these subcommands
> take a common set of options for consistency.
> 
> Instead of reimplementing the same features for the common options
> within every command, I thought it would be nice to factor out the
> common options to some function like: parse_common_options().   After
> that, I would then parse whatever was leftover that were specific
> command options.

One way to do it is to build several OptionParser objects -- one for
each sub-command's unique options, and one for the "global" options
common to each sub-command.  Then you need to figure out how to sneak
Option objects from the "global" OptionParser into each sub-command's
OptionParser just before parsing the args for that sub-command.

Another approach is to use OptionGroup (added by David Goodger for Optik
1.4): have a bunch of OptionGroup objects sitting around at your
disposal, and plug them into your OptionParser as needed.

Either approach will require reading some code to figure out how Optik
stores things internally (it's not very complicated).  Please let me
know what interfaces are lacking to do this cleanly -- I'm pretty sure
it's *possible* to do this, but I've never tried, so undoubtedly there
are details I missed.

        Greg
-- 
Greg Ward <[email protected]>                         http://www.gerg.ca/
Ward's Rule of Gender Identification:
If I can't tell at a glance, I don't want to know.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf