Mercurial > hg > configuration
changeset 98:91e213025769
handle None type (though its probably a bogus case) and note on future failure upon coercion
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 30 Apr 2012 11:07:17 -0700 |
parents | 0c47bcb63048 |
children | 17001bceec8f |
files | configuration/configuration.py |
diffstat | 1 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/configuration.py Sun Apr 29 19:18:11 2012 -0700 +++ b/configuration/configuration.py Mon Apr 30 11:07:17 2012 -0700 @@ -361,16 +361,28 @@ return getattr(handler, 'take_action', lambda x: 1) def option_type(self, name): + """get the type of an option named `name`""" + value = self.option_dict[name] if 'type' in value: return value['type'] if 'default' in value: + default = value['default'] + if default is None: + return None return type(value['default']) def optparse_options(self, parser): """add optparse options to a OptionParser instance""" for key, value in self.items(): - handler = self.types[self.option_type(key)] + try: + handler = self.types[self.option_type(key)] + except: + # XXX print this for now + # ultimately, if an option can't be coerced to a type + # we should just not add a CLI handler for it + print key, value + raise args, kw = handler(key, value) if not args: # No CLI interface