Mercurial > hg > MakeItSo
comparison makeitso/cli.py @ 61:57f9b0349192
wait, its completely silly to print the variables since OptionParser already does that
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 06 Jan 2011 17:14:22 -0800 |
| parents | da0d8c5c5157 |
| children | 30100690ad3f |
comparison
equal
deleted
inserted
replaced
| 60:da0d8c5c5157 | 61:57f9b0349192 |
|---|---|
| 21 # add the variables as options | 21 # add the variables as options |
| 22 for variable in self.template_class.vars: | 22 for variable in self.template_class.vars: |
| 23 parser.add_option('--%s' % variable.name, dest=variable.name, | 23 parser.add_option('--%s' % variable.name, dest=variable.name, |
| 24 default=variable.default, | 24 default=variable.default, |
| 25 help=variable.description) | 25 help=variable.description) |
| 26 | |
| 27 # add CLI-specific options | |
| 28 # should start with '_' to indicate reserved | |
| 29 parser.add_option('--variables', dest='_print_variables', | |
| 30 action='store_true', default=False, | |
| 31 help="display variables in the template") | |
| 32 return parser | 26 return parser |
| 33 | 27 |
| 34 def parse(self): | 28 def parse(self): |
| 35 parser = self.parser() | 29 parser = self.parser() |
| 36 options, args = parser.parse_args() | 30 options, args = parser.parse_args() |
| 37 | 31 |
| 38 # print the variables for the templates | |
| 39 if options._print_variables: | |
| 40 | |
| 41 # find all variables | |
| 42 template = self.template() | |
| 43 variables = template.variables() | |
| 44 | |
| 45 # print them | |
| 46 for variable in sorted(variables): | |
| 47 print variable | |
| 48 return | |
| 49 | |
| 50 # ensure output is given | 32 # ensure output is given |
| 51 if len(args) != 1: | 33 if len(args) != 1: |
| 52 parser.error("Please specify one output") | 34 parser.error("Please specify a single output destination") |
| 53 | 35 |
| 54 # template variables | 36 # template variables |
| 55 variables = dict([(key, value) | 37 variables = dict([(key, value) |
| 56 for key, value in options.__dict__.items() | 38 for key, value in options.__dict__.items() |
| 57 if not key.startswith('_')]) | 39 if not key.startswith('_')]) |
