group switches & option conflict?
Francisco Borges <[email protected]> Fri, 9 Dec 2005 20:07:06 +0100
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Organization | Alfa Informatica - Rijksuniversiteit Groningen |
| Message-ID | <[email protected]> |
Hello!
I'm a long time user of optparse/optiek. Though I really like it,
one thing I always missed is the ability of automatically having options
as valid or invalid depending of context.
There are two cases I see this as being useful:
================================
CASE 1:
Turning "on" certain groups of options though some action swicht:
$ wiel train --train-specific-option
which is ok then but should lead to an error when if you use:
$ wiel.py test --train-specific-option
Which /could/ also allow more specific help messages:
wiel.py train --help
[prints only general + 'train' related options, but not 'test' related]
This could be done by adding some "switch" or "action" argument to the
existing groups:
grp_inp = OptionGroup(prs, 'Training Options', switch="train")
another possibility would be to use groups as templates, to make it
simple to create actions as "this_that" that would accept all
options from "this" and "that".
==================================
CASE 2
The ability to set some options as required/conflicting depending on
other options. Such as in:
- when two options conflict:
Implemented with a add_conflict method:
prs = OptionParser()
prs.add_option('--svmNU', action='store', type='float', metavar='NU',
dest='svmNU', default=None, help='Set nu for the \
nuSVM algorithm.')
prs.add_option('--svmEpsilon', action='store', type='float', default=None,
dest='svmEpsilon', help='epsilon of the epsilon-SVR algorithm')
psr.add_conflict(["svmNU","svmEpsilon"])
Forbidding the use of these two options at the same time, i.e. if it
makes no sense to use the two together, give an error and to let the
user know it.
(Im not so sure about this last one.)
- when one option conflicts with the value of another option:
Here the method "add_conflict_value" would take 3 args:
First and second variable, and a third argument that could be:
a) a list: with choices that would conflict.
psr.add_conflict_value('nu', 'algorithm', ['eSVR', 'sSVC'])
b) a callback function: to return True if conflict exists.
psr.add_conflict_value('nu', 'algorithm', ['eSVR', 'sSVC'])
==============================================================
That was it.
Any comments? Suggestions? Opinions?
--
Francisco
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click