Mercurial > hg > CommandParser
comparison commandparser/command.py @ 3:406183d93e48
whitespace
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 30 Mar 2012 09:13:06 -0700 |
parents | d36032625794 |
children | 5f31e56eebb6 |
comparison
equal
deleted
inserted
replaced
2:d36032625794 | 3:406183d93e48 |
---|---|
41 def add_option(self, *args, **kwargs): | 41 def add_option(self, *args, **kwargs): |
42 kwargs['default'] = Undefined(kwargs.get('default')) | 42 kwargs['default'] = Undefined(kwargs.get('default')) |
43 OptionParser.add_option(self, *args, **kwargs) | 43 OptionParser.add_option(self, *args, **kwargs) |
44 | 44 |
45 def print_help(self): | 45 def print_help(self): |
46 | 46 |
47 OptionParser.print_help(self) | 47 OptionParser.print_help(self) |
48 | 48 |
49 # short descriptions for commands | 49 # short descriptions for commands |
50 command_descriptions = [dict(name=i, | 50 command_descriptions = [dict(name=i, |
51 description=self.commands[i]['doc'].strip().split('\n',1)[0]) | 51 description=self.commands[i]['doc'].strip().split('\n',1)[0]) |
52 for i in self.commands.keys()] | 52 for i in self.commands.keys()] |
53 command_descriptions.append(dict(name='help', description='print help for a given command')) | 53 command_descriptions.append(dict(name='help', description='print help for a given command')) |
59 print | 59 print |
60 print description | 60 print description |
61 | 61 |
62 def parse(self, args=sys.argv[1:]): | 62 def parse(self, args=sys.argv[1:]): |
63 """global parse step""" | 63 """global parse step""" |
64 | 64 |
65 self.options, args = self.parse_args(args) | 65 self.options, args = self.parse_args(args) |
66 | 66 |
67 # help/sanity check -- should probably be separated | 67 # help/sanity check -- should probably be separated |
68 if not len(args): | 68 if not len(args): |
69 self.print_help() | 69 self.print_help() |
182 def doc2arghelp(self, docstring, decoration='-', delimeter=':'): | 182 def doc2arghelp(self, docstring, decoration='-', delimeter=':'): |
183 """ | 183 """ |
184 Parse a docstring and get at the section describing arguments | 184 Parse a docstring and get at the section describing arguments |
185 - decoration: decoration character | 185 - decoration: decoration character |
186 - delimeter: delimter character | 186 - delimeter: delimter character |
187 | 187 |
188 Yields a tuple of the stripped docstring and the arguments help | 188 Yields a tuple of the stripped docstring and the arguments help |
189 dictionary | 189 dictionary |
190 """ | 190 """ |
191 lines = [ i.strip() for i in docstring.split('\n') ] | 191 lines = [ i.strip() for i in docstring.split('\n') ] |
192 argdict = {} | 192 argdict = {} |
235 help=help) | 235 help=help) |
236 else: | 236 else: |
237 if value is not None: | 237 if value is not None: |
238 help += ' [DEFAULT: %s]' % value | 238 help += ' [DEFAULT: %s]' % value |
239 parser.add_option('--%s' % key, help=help, default=value) | 239 parser.add_option('--%s' % key, help=help, default=value) |
240 | 240 |
241 return parser | 241 return parser |