3 def attr_to_option(variable):
5 Converts Python attribute names to command line options.
7 >>> attr_to_option("foo_bar")
10 return '--' + variable.replace('_', '-')
12 class Controller(object):
14 Simple controller that actually delegates to :class:`optparse.OptionParser`.
16 def __init__(self, dir, schema):
19 def push(self, parser):
20 """Pushes arg schema to :class:`optparse.OptionParser`."""
21 required = optparse.OptionGroup(parser, "Required Arguments (SETUPARGS)")
22 optional = optparse.OptionGroup(parser, "Optional Arguments (SETUPARGS)")
23 for arg in self.schema.args.values():
24 group = arg.name in self.schema.provides and optional or required
25 group.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type,
26 default=None, help=arg.help)
27 parser.add_option_group(required)
28 parser.add_option_group(optional)
29 def handle(self, options):
31 Performs post-processing for the options, including throwing
32 errors if not all arguments are specified.
34 self.schema.load(options)