Mercurial > hg
diff mercurial/commands.py @ 1519:5b19dea9d4fd
Merge with TAH
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 09 Nov 2005 12:52:05 -0800 |
parents | 0b1b029b4de3 ac4ca6bf2383 |
children | 95ee4f12fbd9 d07d729ce306 |
line wrap: on
line diff
--- 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')