diff --git a/hgext/alias.py b/hgext/alias.py --- a/hgext/alias.py +++ b/hgext/alias.py @@ -9,9 +9,8 @@ To use, create entries in your hgrc of t mycmd = cmd --args ''' -from mercurial.cmdutil import findcmd, UnknownCommand, AmbiguousCommand -from mercurial import commands from mercurial.i18n import _ +from mercurial import commands, cmdutil, error cmdtable = {} @@ -43,16 +42,16 @@ class lazycommand(object): return try: - self._cmd = findcmd(self._target, commands.table, False)[1] + self._cmd = cmdutil.findcmd(self._target, commands.table, False)[1] if self._cmd == self: raise RecursiveCommand() if self._target in commands.norepo.split(' '): commands.norepo += ' %s' % self._name return - except UnknownCommand: + except error.UnknownCommand: msg = _('*** [alias] %s: command %s is unknown') % \ (self._name, self._target) - except AmbiguousCommand: + except error.AmbiguousCommand: msg = _('*** [alias] %s: command %s is ambiguous') % \ (self._name, self._target) except RecursiveCommand: diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -8,16 +8,11 @@ from node import hex, nullid, nullrev, short from i18n import _ import os, sys, bisect, stat -import mdiff, bdiff, util, templater, templatefilters, patch, errno +import mdiff, bdiff, util, templater, templatefilters, patch, errno, error import match as _match revrangesep = ':' -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 findpossible(cmd, table, strict=False): """ Return cmd -> (aliases, command table entry) @@ -57,12 +52,12 @@ def findcmd(cmd, table, strict=True): if len(choice) > 1: clist = choice.keys() clist.sort() - raise AmbiguousCommand(cmd, clist) + raise error.AmbiguousCommand(cmd, clist) if choice: return choice.values()[0] - raise UnknownCommand(cmd) + raise error.UnknownCommand(cmd) def bail_if_changed(repo): if repo.dirstate.parents()[1] != nullid: diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1321,7 +1321,7 @@ def help_(ui, name=None, with_version=Fa try: aliases, i = cmdutil.findcmd(name, table, False) - except cmdutil.AmbiguousCommand, inst: + except error.AmbiguousCommand, inst: select = lambda c: c.lstrip('^').startswith(inst.args[0]) helplist(_('list of commands:\n\n'), select) return @@ -1410,7 +1410,7 @@ def help_(ui, name=None, with_version=Fa if name in names: break else: - raise cmdutil.UnknownCommand(name) + raise error.UnknownCommand(name) # description if not doc: @@ -1425,7 +1425,7 @@ def help_(ui, name=None, with_version=Fa try: mod = extensions.find(name) except KeyError: - raise cmdutil.UnknownCommand(name) + raise error.UnknownCommand(name) doc = gettext(mod.__doc__) or _('no help text available') doc = doc.splitlines(0) @@ -1450,7 +1450,7 @@ def help_(ui, name=None, with_version=Fa f(name) i = None break - except cmdutil.UnknownCommand, inst: + except error.UnknownCommand, inst: i = inst if i: raise i diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -55,10 +55,10 @@ def _runcatch(ui, args): else: ui.warn(_("hg: %s\n") % inst.args[1]) commands.help_(ui, 'shortlist') - except cmdutil.AmbiguousCommand, inst: + except error.AmbiguousCommand, inst: ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % (inst.args[0], " ".join(inst.args[1]))) - except cmdutil.UnknownCommand, inst: + except error.UnknownCommand, inst: ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) commands.help_(ui, 'shortlist') except error.RepoError, inst: diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -50,3 +50,9 @@ class LockUnavailable(LockError): class ResponseError(Exception): """Raised to print an error with part of output and exit.""" +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.""" +