changeset 1848:bb70ffebe77b

show choices on ambiguous commands
author TK Soh <teekaysoh@yahoo.com>
date Tue, 07 Mar 2006 08:05:17 +0100
parents 4d2791f4ef80
children 360d0f8d9d6f
files mercurial/commands.py
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Mar 06 21:06:53 2006 -0800
+++ b/mercurial/commands.py	Tue Mar 07 08:05:17 2006 +0100
@@ -2678,23 +2678,22 @@
 
 def find(cmd):
     """Return (aliases, command table entry) for command string."""
-    choice = None
-    count = 0
+    choice = []
     for e in table.keys():
         aliases = e.lstrip("^").split("|")
         if cmd in aliases:
             return aliases, table[e]
         for a in aliases:
             if a.startswith(cmd):
-                count += 1
-                choice = aliases, table[e]
+                choice.append([aliases, table[e]])
                 break
 
-    if count > 1:
-        raise AmbiguousCommand(cmd)
+    if len(choice) > 1:
+        clist = [x[0][0] for x in choice]
+        raise AmbiguousCommand(cmd, clist)
 
     if choice:
-        return choice
+        return choice[0]
 
     raise UnknownCommand(cmd)
 
@@ -2806,7 +2805,8 @@
             help_(u, 'shortlist')
         sys.exit(-1)
     except AmbiguousCommand, inst:
-        u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
+        u.warn(_("hg: command '%s' is ambiguous:\n    %s\n") % 
+                (inst.args[0], " ".join(inst.args[1])))
         sys.exit(1)
     except UnknownCommand, inst:
         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
@@ -2941,7 +2941,8 @@
         u.warn(_("%s: invalid arguments\n") % cmd)
         help_(u, cmd)
     except AmbiguousCommand, inst:
-        u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
+        u.warn(_("hg: command '%s' is ambiguous:\n    %s\n") % 
+                (inst.args[0], " ".join(inst.args[1])))
         help_(u, 'shortlist')
     except UnknownCommand, inst:
         u.warn(_("hg: unknown command '%s'\n") % inst.args[0])