Show More
@@ -9,9 +9,8 b' To use, create entries in your hgrc of t' | |||||
9 | mycmd = cmd --args |
|
9 | mycmd = cmd --args | |
10 | ''' |
|
10 | ''' | |
11 |
|
11 | |||
12 | from mercurial.cmdutil import findcmd, UnknownCommand, AmbiguousCommand |
|
|||
13 | from mercurial import commands |
|
|||
14 | from mercurial.i18n import _ |
|
12 | from mercurial.i18n import _ | |
|
13 | from mercurial import commands, cmdutil, error | |||
15 |
|
14 | |||
16 | cmdtable = {} |
|
15 | cmdtable = {} | |
17 |
|
16 | |||
@@ -43,16 +42,16 b' class lazycommand(object):' | |||||
43 | return |
|
42 | return | |
44 |
|
43 | |||
45 | try: |
|
44 | try: | |
46 | self._cmd = findcmd(self._target, commands.table, False)[1] |
|
45 | self._cmd = cmdutil.findcmd(self._target, commands.table, False)[1] | |
47 | if self._cmd == self: |
|
46 | if self._cmd == self: | |
48 | raise RecursiveCommand() |
|
47 | raise RecursiveCommand() | |
49 | if self._target in commands.norepo.split(' '): |
|
48 | if self._target in commands.norepo.split(' '): | |
50 | commands.norepo += ' %s' % self._name |
|
49 | commands.norepo += ' %s' % self._name | |
51 | return |
|
50 | return | |
52 | except UnknownCommand: |
|
51 | except error.UnknownCommand: | |
53 | msg = _('*** [alias] %s: command %s is unknown') % \ |
|
52 | msg = _('*** [alias] %s: command %s is unknown') % \ | |
54 | (self._name, self._target) |
|
53 | (self._name, self._target) | |
55 | except AmbiguousCommand: |
|
54 | except error.AmbiguousCommand: | |
56 | msg = _('*** [alias] %s: command %s is ambiguous') % \ |
|
55 | msg = _('*** [alias] %s: command %s is ambiguous') % \ | |
57 | (self._name, self._target) |
|
56 | (self._name, self._target) | |
58 | except RecursiveCommand: |
|
57 | except RecursiveCommand: |
@@ -8,16 +8,11 b'' | |||||
8 | from node import hex, nullid, nullrev, short |
|
8 | from node import hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import os, sys, bisect, stat |
|
10 | import os, sys, bisect, stat | |
11 | import mdiff, bdiff, util, templater, templatefilters, patch, errno |
|
11 | import mdiff, bdiff, util, templater, templatefilters, patch, errno, error | |
12 | import match as _match |
|
12 | import match as _match | |
13 |
|
13 | |||
14 | revrangesep = ':' |
|
14 | revrangesep = ':' | |
15 |
|
15 | |||
16 | class UnknownCommand(Exception): |
|
|||
17 | """Exception raised if command is not in the command table.""" |
|
|||
18 | class AmbiguousCommand(Exception): |
|
|||
19 | """Exception raised if command shortcut matches more than one command.""" |
|
|||
20 |
|
||||
21 | def findpossible(cmd, table, strict=False): |
|
16 | def findpossible(cmd, table, strict=False): | |
22 | """ |
|
17 | """ | |
23 | Return cmd -> (aliases, command table entry) |
|
18 | Return cmd -> (aliases, command table entry) | |
@@ -57,12 +52,12 b' def findcmd(cmd, table, strict=True):' | |||||
57 | if len(choice) > 1: |
|
52 | if len(choice) > 1: | |
58 | clist = choice.keys() |
|
53 | clist = choice.keys() | |
59 | clist.sort() |
|
54 | clist.sort() | |
60 | raise AmbiguousCommand(cmd, clist) |
|
55 | raise error.AmbiguousCommand(cmd, clist) | |
61 |
|
56 | |||
62 | if choice: |
|
57 | if choice: | |
63 | return choice.values()[0] |
|
58 | return choice.values()[0] | |
64 |
|
59 | |||
65 | raise UnknownCommand(cmd) |
|
60 | raise error.UnknownCommand(cmd) | |
66 |
|
61 | |||
67 | def bail_if_changed(repo): |
|
62 | def bail_if_changed(repo): | |
68 | if repo.dirstate.parents()[1] != nullid: |
|
63 | if repo.dirstate.parents()[1] != nullid: |
@@ -1321,7 +1321,7 b' def help_(ui, name=None, with_version=Fa' | |||||
1321 |
|
1321 | |||
1322 | try: |
|
1322 | try: | |
1323 | aliases, i = cmdutil.findcmd(name, table, False) |
|
1323 | aliases, i = cmdutil.findcmd(name, table, False) | |
1324 |
except |
|
1324 | except error.AmbiguousCommand, inst: | |
1325 | select = lambda c: c.lstrip('^').startswith(inst.args[0]) |
|
1325 | select = lambda c: c.lstrip('^').startswith(inst.args[0]) | |
1326 | helplist(_('list of commands:\n\n'), select) |
|
1326 | helplist(_('list of commands:\n\n'), select) | |
1327 | return |
|
1327 | return | |
@@ -1410,7 +1410,7 b' def help_(ui, name=None, with_version=Fa' | |||||
1410 | if name in names: |
|
1410 | if name in names: | |
1411 | break |
|
1411 | break | |
1412 | else: |
|
1412 | else: | |
1413 |
raise |
|
1413 | raise error.UnknownCommand(name) | |
1414 |
|
1414 | |||
1415 | # description |
|
1415 | # description | |
1416 | if not doc: |
|
1416 | if not doc: | |
@@ -1425,7 +1425,7 b' def help_(ui, name=None, with_version=Fa' | |||||
1425 | try: |
|
1425 | try: | |
1426 | mod = extensions.find(name) |
|
1426 | mod = extensions.find(name) | |
1427 | except KeyError: |
|
1427 | except KeyError: | |
1428 |
raise |
|
1428 | raise error.UnknownCommand(name) | |
1429 |
|
1429 | |||
1430 | doc = gettext(mod.__doc__) or _('no help text available') |
|
1430 | doc = gettext(mod.__doc__) or _('no help text available') | |
1431 | doc = doc.splitlines(0) |
|
1431 | doc = doc.splitlines(0) | |
@@ -1450,7 +1450,7 b' def help_(ui, name=None, with_version=Fa' | |||||
1450 | f(name) |
|
1450 | f(name) | |
1451 | i = None |
|
1451 | i = None | |
1452 | break |
|
1452 | break | |
1453 |
except |
|
1453 | except error.UnknownCommand, inst: | |
1454 | i = inst |
|
1454 | i = inst | |
1455 | if i: |
|
1455 | if i: | |
1456 | raise i |
|
1456 | raise i |
@@ -55,10 +55,10 b' def _runcatch(ui, args):' | |||||
55 | else: |
|
55 | else: | |
56 | ui.warn(_("hg: %s\n") % inst.args[1]) |
|
56 | ui.warn(_("hg: %s\n") % inst.args[1]) | |
57 | commands.help_(ui, 'shortlist') |
|
57 | commands.help_(ui, 'shortlist') | |
58 |
except |
|
58 | except error.AmbiguousCommand, inst: | |
59 | ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
59 | ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
60 | (inst.args[0], " ".join(inst.args[1]))) |
|
60 | (inst.args[0], " ".join(inst.args[1]))) | |
61 |
except |
|
61 | except error.UnknownCommand, inst: | |
62 | ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
62 | ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
63 | commands.help_(ui, 'shortlist') |
|
63 | commands.help_(ui, 'shortlist') | |
64 | except error.RepoError, inst: |
|
64 | except error.RepoError, inst: |
@@ -50,3 +50,9 b' class LockUnavailable(LockError):' | |||||
50 | class ResponseError(Exception): |
|
50 | class ResponseError(Exception): | |
51 | """Raised to print an error with part of output and exit.""" |
|
51 | """Raised to print an error with part of output and exit.""" | |
52 |
|
52 | |||
|
53 | class UnknownCommand(Exception): | |||
|
54 | """Exception raised if command is not in the command table.""" | |||
|
55 | ||||
|
56 | class AmbiguousCommand(Exception): | |||
|
57 | """Exception raised if command shortcut matches more than one command.""" | |||
|
58 |
General Comments 0
You need to be logged in to leave comments.
Login now