changeset 19:9090fe0cdb72

add help command
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 09 Dec 2010 13:51:46 -0800
parents 9fac43403d7e
children c819c8388ad1
files bzconsole/command.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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()