Mercurial > hg > configuration
changeset 44:b3db38b14567
stub adding an option of keeping track of what is parsed
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 27 Mar 2012 11:33:09 -0700 |
parents | f09982d47b3c |
children | bb5f4eeb56c5 |
files | configuration/config.py |
diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/config.py Tue Mar 27 11:19:33 2012 -0700 +++ b/configuration/config.py Tue Mar 27 11:33:09 2012 -0700 @@ -22,7 +22,7 @@ except ImportError: yaml = None -__all__ = ['Configuration', 'configuration_providers', 'types', 'MissingValueException'] +__all__ = ['Configuration', 'configuration_providers', 'types', 'MissingValueException', 'ConfigurationProviderException', 'ConfigurationOption'] ### exceptions @@ -87,6 +87,18 @@ __all__.extend([i.__class__.__name__ for i in configuration_providers]) +### optparse interface + +class ConfigurationOption(optparse.Option): + """option that keeps track if it is seen""" + # TODO: this should be configurable or something + def take_action(self, action, dest, opt, value, values, parser): + """add the parsed option to the set of things parsed""" + optparse.Option.take_action(self, action, dest, opt, value, values, parser) + if not hasattr(parser, 'parsed'): + parser.parsed = set() + parser.parsed.add(dest) + ### plugins for option types ### TODO: this could use a bit of thought ### They should probably be classes @@ -257,6 +269,7 @@ - dump : option for dumping configuration - parser_args : arguments to the OptionParser constructor """ + if 'description' not in parser_args: parser_args['description'] = getattr(self, '__doc__', '') if 'formatter' not in parser_args: