diff options
author | Sylvain <syt@logilab.fr> | 2006-09-19 12:41:30 +0200 |
---|---|---|
committer | Sylvain <syt@logilab.fr> | 2006-09-19 12:41:30 +0200 |
commit | d2f29935e7601247b1a73eec79f262a77805f20e (patch) | |
tree | 4ed2d2e64de3f5ae7ec8feac75e75fe1c69fc2ba | |
parent | d9eccc57048c373a6c37d51a77a827aa4499b75c (diff) | |
download | logilab-common-d2f29935e7601247b1a73eec79f262a77805f20e.tar.gz |
fix named option handling
-rw-r--r-- | configuration.py | 6 | ||||
-rw-r--r-- | optik_ext.py | 15 |
2 files changed, 21 insertions, 0 deletions
diff --git a/configuration.py b/configuration.py index 81934de..1337cd4 100644 --- a/configuration.py +++ b/configuration.py @@ -639,6 +639,12 @@ class OptionsProviderMixIn: value = convert(value, opt_dict, opt_name) if action is None: action = opt_dict.get('action', 'store') + if opt_dict.get('type') == 'named': # XXX need specific handling + optname = self.option_name(opt_name, opt_dict) + currentvalue = getattr(self.config, optname, None) + if currentvalue: + currentvalue.update(value) + value = currentvalue if action == 'store': setattr(self.config, self.option_name(opt_name, opt_dict), value) elif action in ('store_true', 'count'): diff --git a/optik_ext.py b/optik_ext.py index 6eb73e6..5ce2dfd 100644 --- a/optik_ext.py +++ b/optik_ext.py @@ -186,6 +186,21 @@ class Option(BaseOption): "must not supply choices for type %r" % self.type, self) BaseOption.CHECK_METHODS[2] = _check_choice + + def process(self, opt, value, values, parser): + # First, convert the value(s) to the right type. Howl if any + # value(s) are bogus. + value = self.convert_value(opt, value) + if self.type == 'named': + existant = getattr(values, self.dest) + if existant: + existant.update(value) + value = existant + # And then take whatever action is expected of us. + # This is a separate method to make life easier for + # subclasses to add new actions. + return self.take_action( + self.action, self.dest, opt, value, values, parser) class OptionParser(BaseParser): """override optik.OptionParser to use our Option class |