error: move UnknownCommand and AmbiguousCommand
authorMatt Mackall <mpm@selenic.com>
Mon, 12 Jan 2009 11:39:38 -0600
changeset 7643 9a1ea6587557
parent 7642 84346894def8
child 7644 182b7114d35a
error: move UnknownCommand and AmbiguousCommand
hgext/alias.py
mercurial/cmdutil.py
mercurial/commands.py
mercurial/dispatch.py
mercurial/error.py
--- a/hgext/alias.py	Mon Jan 12 11:28:30 2009 -0600
+++ b/hgext/alias.py	Mon Jan 12 11:39:38 2009 -0600
@@ -9,9 +9,8 @@
 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 @@
             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:
--- a/mercurial/cmdutil.py	Mon Jan 12 11:28:30 2009 -0600
+++ b/mercurial/cmdutil.py	Mon Jan 12 11:39:38 2009 -0600
@@ -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 @@
     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:
--- a/mercurial/commands.py	Mon Jan 12 11:28:30 2009 -0600
+++ b/mercurial/commands.py	Mon Jan 12 11:39:38 2009 -0600
@@ -1321,7 +1321,7 @@
 
         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 @@
             if name in names:
                 break
         else:
-            raise cmdutil.UnknownCommand(name)
+            raise error.UnknownCommand(name)
 
         # description
         if not doc:
@@ -1425,7 +1425,7 @@
         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 @@
                 f(name)
                 i = None
                 break
-            except cmdutil.UnknownCommand, inst:
+            except error.UnknownCommand, inst:
                 i = inst
         if i:
             raise i
--- a/mercurial/dispatch.py	Mon Jan 12 11:28:30 2009 -0600
+++ b/mercurial/dispatch.py	Mon Jan 12 11:39:38 2009 -0600
@@ -55,10 +55,10 @@
         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:
--- a/mercurial/error.py	Mon Jan 12 11:28:30 2009 -0600
+++ b/mercurial/error.py	Mon Jan 12 11:39:38 2009 -0600
@@ -50,3 +50,9 @@
 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."""
+