changeset 17:a78ab14ae376

separate thing to add options to its own function
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Mar 2012 12:04:49 -0700
parents b7e7f450ad1a
children d8871956536e
files configuration/config.py
diffstat 1 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/config.py	Mon Mar 26 11:10:30 2012 -0700
+++ b/configuration/config.py	Mon Mar 26 12:04:49 2012 -0700
@@ -72,26 +72,8 @@
         self.config.update(config)
         # TODO: option to extend; augment lists/dicts
 
-    def parser(self, configuration_provider_option=None, **parser_args):
-        """
-        return OptionParser for this Configuration instance
-        - configuration_provider_options : option for configuration files [TODO]
-        (also TODO: a special value that equates to the first file extension value
-        for the configuration_providers)
-        - 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:
-                class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
-                    """description formatter for console script entry point"""
-                    def format_description(self, description):
-                        if description:
-                            return description.strip() + '\n'
-                        else:
-                            return ''
-                parser_args['formatter'] = PlainDescriptionFormatter()
-        parser = optparse.OptionParser(**parser_args)
+    def optparse_options(self, parser):
+        """add optparse options to a OptionParser instance"""
         for key, value in self.items():
             # TODO: move adding options to a separate function
 
@@ -113,6 +95,28 @@
             kw['help'] = help
             kw['action'] = 'store' # TODO: types
             parser.add_option(*args, **kw)
+
+    def parser(self, configuration_provider_option=None, **parser_args):
+        """
+        return OptionParser for this Configuration instance
+        - configuration_provider_options : option for configuration files [TODO]
+        (also TODO: a special value that equates to the first file extension value
+        for the configuration_providers)
+        - 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:
+                class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
+                    """description formatter for console script entry point"""
+                    def format_description(self, description):
+                        if description:
+                            return description.strip() + '\n'
+                        else:
+                            return ''
+                parser_args['formatter'] = PlainDescriptionFormatter()
+        parser = optparse.OptionParser(**parser_args)
+        self.optparse_options(parser)
         return parser
 
 def main(args=sys.argv[:]):