# HG changeset patch # User Jeff Hammel # Date 1291931506 28800 # Node ID 9090fe0cdb720ee7b9df354e83ed0b3599e6a7df # Parent 9fac43403d7e035471f5c286659e91239845880e add help command diff -r 9fac43403d7e -r 9090fe0cdb72 bzconsole/command.py --- a/bzconsole/command.py Tue Dec 07 10:21:08 2010 -0800 +++ b/bzconsole/command.py Thu Dec 09 13:51:46 2010 -0800 @@ -32,14 +32,15 @@ self.disable_interspersed_args() def print_help(self): - # XXX should probably use the optparse formatters to help out here OptionParser.print_help(self) # short descriptions for commands command_descriptions = [dict(name=i, description=self.commands[i]['doc'].strip().split('\n',1)[0]) - for i in sorted(self.commands.keys())] + for i in self.commands.keys()] + command_descriptions.append(dict(name='help', description='print help for a given command')) + command_descriptions.sort(key=lambda x: x['name']) max_len = max([len(i['name']) for i in command_descriptions]) description = "Commands: \n%s" % ('\n'.join([' %s%s %s' % (description['name'], ' ' * (max_len - len(description['name'])), description['description']) for description in command_descriptions])) @@ -58,7 +59,9 @@ sys.exit(0) if args[0] == 'help': if len(args) == 2: - if args[1] in self.commands: + if args[1] == 'help': + self.print_help() + elif args[1] in self.commands: name = args[1] commandparser = self.command2parser(name) commandparser.print_help()