summaryrefslogtreecommitdiff
path: root/cliff/help.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-06 18:26:11 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-06 18:26:11 -0400
commite31a7f664a97c3e9600279d52df4cb6dab5353b7 (patch)
tree182bef9c9aeeb487667f0b974bcbf006dc6d9c09 /cliff/help.py
parent45fbf20de2a81dfa36ece9e91413f010ca9dafc3 (diff)
downloadcliff-tablib-e31a7f664a97c3e9600279d52df4cb6dab5353b7.tar.gz
make help list commands if none match exactly; fixes #8
Diffstat (limited to 'cliff/help.py')
-rw-r--r--cliff/help.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/cliff/help.py b/cliff/help.py
index 2ac8bc4..1e4793e 100644
--- a/cliff/help.py
+++ b/cliff/help.py
@@ -38,7 +38,20 @@ class HelpCommand(Command):
def run(self, parsed_args):
if parsed_args.cmd:
- cmd_factory, cmd_name, search_args = self.app.command_manager.find_command(parsed_args.cmd)
+ try:
+ cmd_factory, cmd_name, search_args = self.app.command_manager.find_command(parsed_args.cmd)
+ except ValueError:
+ # Did not find an exact match
+ cmd = parsed_args.cmd[0]
+ fuzzy_matches = [k[0] for k in self.app.command_manager
+ if k[0].startswith(cmd)
+ ]
+ if not fuzzy_matches:
+ raise
+ self.app.stdout.write('Command "%s" matches:\n' % cmd)
+ for fm in fuzzy_matches:
+ self.app.stdout.write(' %s\n' % fm)
+ return
cmd = cmd_factory(self.app, search_args)
full_name = (cmd_name
if self.app.interactive_mode