changeset 98:37f92ae8f999

separate out variable getting to its own function
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 11:35:38 -0800
parents 3eb34cad5858
children d9c6e26a42ff
files makeitso/cli.py
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/makeitso/cli.py	Tue Jan 11 10:51:22 2011 -0800
+++ b/makeitso/cli.py	Tue Jan 11 11:35:38 2011 -0800
@@ -15,7 +15,7 @@
     """
     return a command line parser for the template
     """
-    usage = '%prog [options] output'
+    usage = getattr(self, 'usage', '%prog [options] output')
     description = getattr(self.template_class, 'description', None)
     parser = OptionParser(usage=usage, description=description)
 
@@ -29,6 +29,14 @@
                         help=description)
     return parser
 
+  def get_variables(self, options):
+    """
+    return variables from (parsed) options
+    """
+    return dict([(key, value)
+                 for key, value in options.__dict__.items()
+                 if not key.startswith('_')])
+
   def parse(self, args=None, parser=None, options=None):
 
     # parse the command line
@@ -41,11 +49,9 @@
       parser.error("Please specify a single output destination")
 
     # template variables
-    variables = dict([(key, value)
-                      for key, value in options.__dict__.items()
-                      if not key.startswith('_')])
-
-    #
+    variables = self.get_variables(options)
+    
+    # return the variables and the output
     return variables, args[0]
     
   def __call__(self, *args):