comparison makeitso/cli.py @ 95:e74baa8e6df4

fix CLI interface a bit....write a test for it
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 09:06:25 -0800
parents cb6c54b1adf3
children 37f92ae8f999
comparison
equal deleted inserted replaced
94:b6a46332cced 95:e74baa8e6df4
27 parser.add_option('--%s' % variable.name, dest=variable.name, 27 parser.add_option('--%s' % variable.name, dest=variable.name,
28 default=variable.default, 28 default=variable.default,
29 help=description) 29 help=description)
30 return parser 30 return parser
31 31
32 def parse(self, parser=None, options=None, args=None): 32 def parse(self, args=None, parser=None, options=None):
33 33
34 # parse the command line 34 # parse the command line
35 if not parser or not options or not args: 35 if not parser or not options:
36 parser = self.parser() 36 parser = self.parser()
37 options, args = parser.parse_args() 37 options, args = parser.parse_args(args=args)
38 38
39 # ensure output is given 39 # ensure output is given
40 if len(args) != 1: 40 if len(args) != 1:
41 parser.error("Please specify a single output destination") 41 parser.error("Please specify a single output destination")
42 42
43 # template variables 43 # template variables
44 variables = dict([(key, value) 44 variables = dict([(key, value)
45 for key, value in options.__dict__.items() 45 for key, value in options.__dict__.items()
46 if not key.startswith('_')]) 46 if not key.startswith('_')])
47
48 #
49 return variables, args[0]
47 50
48 # instantiate the template 51 def __call__(self, *args):
49 template = self.template_class(output=args[0], variables=variables) 52 variables, output = self.parse(list(args))
50 53 template = self.template_class(variables=variables)
51 return template 54 template.substitute({}, output=output)