From bc37c596074d390ecfdd3eb746e548bccd0d87aa Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Mon, 7 Dec 2009 00:42:52 -0500 Subject: [PATCH] Add capability for subcommand shortcuts --- src/mw/cli.py | 8 +++++++- src/mw/clicommands.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mw/cli.py b/src/mw/cli.py index 7f5b4bc..7dc49c5 100644 --- a/src/mw/cli.py +++ b/src/mw/cli.py @@ -26,6 +26,7 @@ class CLI(object): 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 @@ -34,13 +35,18 @@ class CLI(object): 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] - 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) diff --git a/src/mw/clicommands.py b/src/mw/clicommands.py index 7714893..3657d53 100644 --- a/src/mw/clicommands.py +++ b/src/mw/clicommands.py @@ -38,6 +38,7 @@ class CommandBase(object): 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() @@ -75,6 +76,7 @@ class FetchCommand(CommandBase): 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() -- 2.39.5