--- a/mercurial/commands.py Tue Nov 08 14:22:03 2005 -0800
+++ b/mercurial/commands.py Wed Nov 09 12:52:05 2005 -0800
@@ -15,6 +15,8 @@
class UnknownCommand(Exception):
"""Exception raised if command is not in the command table."""
+class AmbiguousCommand(Exception):
+ """Exception raised if command shortcut matches more than one command."""
def filterfiles(filters, files):
l = [x for x in files if x in filters]
@@ -387,7 +389,7 @@
if with_version:
show_version(ui)
ui.write('\n')
- key, i = find(cmd)
+ aliases, i = find(cmd)
# synopsis
ui.write("%s\n\n" % i[2])
@@ -399,9 +401,8 @@
if not ui.quiet:
# aliases
- aliases = ', '.join(key.split('|')[1:])
- if aliases:
- ui.write(_("\naliases: %s\n") % aliases)
+ if len(aliases) > 1:
+ ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
# options
if i[1]:
@@ -2375,17 +2376,20 @@
" debugindex debugindexdot paths")
def find(cmd):
- choice = []
+ """Return (aliases, command table entry) for command string."""
+ choice = None
for e in table.keys():
aliases = e.lstrip("^").split("|")
if cmd in aliases:
- return e, table[e]
+ return aliases, table[e]
for a in aliases:
if a.startswith(cmd):
- choice.append(e)
- if len(choice) == 1:
- e = choice[0]
- return e, table[e]
+ if choice:
+ raise AmbiguousCommand(cmd)
+ else:
+ choice = aliases, table[e]
+ if choice:
+ return choice
raise UnknownCommand(cmd)
@@ -2423,7 +2427,8 @@
cmd, args = args[0], args[1:]
- i = find(cmd)[1]
+ aliases, i = find(cmd)
+ cmd = aliases[0]
c = list(i[1])
else:
cmd = None
@@ -2503,6 +2508,9 @@
u.warn(_("hg: %s\n") % inst.args[1])
help_(u, 'shortlist')
sys.exit(-1)
+ except AmbiguousCommand, inst:
+ u.warn(_("hg: command '%s' is ambiguous.\n") % inst.args[0])
+ sys.exit(1)
except UnknownCommand, inst:
u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
help_(u, 'shortlist')