]> projects.mako.cc - mw/commitdiff
Add capability for subcommand shortcuts
authorIan Weller <ian@ianweller.org>
Mon, 7 Dec 2009 05:42:52 +0000 (00:42 -0500)
committerIan Weller <ian@ianweller.org>
Mon, 7 Dec 2009 05:42:52 +0000 (00:42 -0500)
src/mw/cli.py
src/mw/clicommands.py

index 7f5b4bcd00cc15003212a3fc02408a0e3c0d223b..7dc49c5600286fdc11688507a9d9b97875f39656 100644 (file)
@@ -26,6 +26,7 @@ class CLI(object):
     def __init__(self):
         self.me = os.path.basename(sys.argv[0])
         self.commands = {}
     def __init__(self):
         self.me = os.path.basename(sys.argv[0])
         self.commands = {}
+        self.shortcuts = {}
         for name in mw.clicommands.__dict__:
             if name == 'CommandBase':
                 continue
         for name in mw.clicommands.__dict__:
             if name == 'CommandBase':
                 continue
@@ -34,13 +35,18 @@ class CLI(object):
                issubclass(clazz, mw.clicommands.CommandBase):
                 cmd = clazz()
                 self.commands[cmd.name] = cmd
                issubclass(clazz, mw.clicommands.CommandBase):
                 cmd = clazz()
                 self.commands[cmd.name] = cmd
+                self.shortcuts[cmd.name] = cmd.shortcuts
 
     def usage(self):
         print 'usage: %s [subcommand]' % self.me
         print
         for name in self.commands:
             cmd = self.commands[name]
 
     def usage(self):
         print 'usage: %s [subcommand]' % self.me
         print
         for name in self.commands:
             cmd = self.commands[name]
-            print("\t%-14s %-25s" % (name, cmd.description))
+            if len(cmd.shortcuts) > 0:
+                full = name + ' (' + ' '.join(cmd.shortcuts) + ')'
+            else:
+                full = name
+            print("\t%-14s %-25s" % (full, cmd.description))
         print
         sys.exit(1)
 
         print
         sys.exit(1)
 
index 77148934227b3f0167dace94254edb04b1113399..3657d532ad18280d37db5bdd90878fede112ec77 100644 (file)
@@ -38,6 +38,7 @@ class CommandBase(object):
                                   dest='use_auth', help='force authentication '
                                   'even if not required')
         self.parser.add_option_group(global_options)
                                   dest='use_auth', help='force authentication '
                                   'even if not required')
         self.parser.add_option_group(global_options)
+        self.shortcuts = []
 
     def main(self):
         (self.options, self.args) = self.parser.parse_args()
 
     def main(self):
         (self.options, self.args) = self.parser.parse_args()
@@ -75,6 +76,7 @@ class FetchCommand(CommandBase):
     def __init__(self):
         usage = '%prog fetch [options] PAGENAME ...'
         CommandBase.__init__(self, 'fetch', 'fetch remote pages', usage)
     def __init__(self):
         usage = '%prog fetch [options] PAGENAME ...'
         CommandBase.__init__(self, 'fetch', 'fetch remote pages', usage)
+        self.shortcuts.append('ft')
 
     def _do_command(self):
         self._die_if_no_init()
 
     def _do_command(self):
         self._die_if_no_init()

Benjamin Mako Hill || Want to submit a patch?