Mercurial > hg > MakeItSo
comparison makeitso/cli.py @ 62:30100690ad3f
display defaults with command line --help option
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 06 Jan 2011 17:49:40 -0800 |
| parents | 57f9b0349192 |
| children | cce0da329f59 |
comparison
equal
deleted
inserted
replaced
| 61:57f9b0349192 | 62:30100690ad3f |
|---|---|
| 1 """ | 1 """ |
| 2 command line parser for MakeItSo | 2 command line parser for MakeItSo |
| 3 """ | 3 """ |
| 4 | 4 |
| 5 from template import Undefined | |
| 5 from optparse import OptionParser | 6 from optparse import OptionParser |
| 6 | 7 |
| 7 class MakeItSoCLI(object): | 8 class MakeItSoCLI(object): |
| 8 """command line interface to a makeitso template""" | 9 """command line interface to a makeitso template""" |
| 9 | 10 |
| 18 description = getattr(self.template_class, 'description', None) | 19 description = getattr(self.template_class, 'description', None) |
| 19 parser = OptionParser(usage=usage, description=description) | 20 parser = OptionParser(usage=usage, description=description) |
| 20 | 21 |
| 21 # add the variables as options | 22 # add the variables as options |
| 22 for variable in self.template_class.vars: | 23 for variable in self.template_class.vars: |
| 24 description = variable.description | |
| 25 if (variable.default is not None) and (variable.default is not Undefined): | |
| 26 description += ' [DEFAULT: %s]' % variable.default | |
| 23 parser.add_option('--%s' % variable.name, dest=variable.name, | 27 parser.add_option('--%s' % variable.name, dest=variable.name, |
| 24 default=variable.default, | 28 default=variable.default, |
| 25 help=variable.description) | 29 help=description) |
| 26 return parser | 30 return parser |
| 27 | 31 |
| 28 def parse(self): | 32 def parse(self): |
| 29 parser = self.parser() | 33 parser = self.parser() |
| 30 options, args = parser.parse_args() | 34 options, args = parser.parse_args() |
