Mercurial > hg > configuration
comparison configuration/configuration.py @ 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 | bfe4234ee6f4 |
children | 17001bceec8f |
comparison
equal
deleted
inserted
replaced
97:0c47bcb63048 | 98:91e213025769 |
---|---|
359 def cli_formatter(self, option): | 359 def cli_formatter(self, option): |
360 handler = self.types[self.option_dict[option].get('type')] | 360 handler = self.types[self.option_dict[option].get('type')] |
361 return getattr(handler, 'take_action', lambda x: 1) | 361 return getattr(handler, 'take_action', lambda x: 1) |
362 | 362 |
363 def option_type(self, name): | 363 def option_type(self, name): |
364 """get the type of an option named `name`""" | |
365 | |
364 value = self.option_dict[name] | 366 value = self.option_dict[name] |
365 if 'type' in value: | 367 if 'type' in value: |
366 return value['type'] | 368 return value['type'] |
367 if 'default' in value: | 369 if 'default' in value: |
370 default = value['default'] | |
371 if default is None: | |
372 return None | |
368 return type(value['default']) | 373 return type(value['default']) |
369 | 374 |
370 def optparse_options(self, parser): | 375 def optparse_options(self, parser): |
371 """add optparse options to a OptionParser instance""" | 376 """add optparse options to a OptionParser instance""" |
372 for key, value in self.items(): | 377 for key, value in self.items(): |
373 handler = self.types[self.option_type(key)] | 378 try: |
379 handler = self.types[self.option_type(key)] | |
380 except: | |
381 # XXX print this for now | |
382 # ultimately, if an option can't be coerced to a type | |
383 # we should just not add a CLI handler for it | |
384 print key, value | |
385 raise | |
374 args, kw = handler(key, value) | 386 args, kw = handler(key, value) |
375 if not args: | 387 if not args: |
376 # No CLI interface | 388 # No CLI interface |
377 continue | 389 continue |
378 parser.add_option(*args, **kw) | 390 parser.add_option(*args, **kw) |