Merge lp:~lifeless/bzr/commandlookup into lp:bzr

Proposed by Robert Collins
Status: Merged
Approved by: Martin Pool
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~lifeless/bzr/commandlookup
Merge into: lp:bzr
Diff against target: 114 lines (+35/-14)
3 files modified
NEWS (+6/-0)
bzrlib/commands.py (+5/-3)
bzrlib/tests/test_commands.py (+24/-11)
To merge this branch: bzr merge lp:~lifeless/bzr/commandlookup
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+20196@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Woo. Nicer UI is nicer.

Revision history for this message
Martin Pool (mbp) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-02-25 06:17:27 +0000
3+++ NEWS 2010-02-26 04:48:17 +0000
4@@ -70,6 +70,12 @@
5 * ``bzr add`` will not add conflict related files unless explicitly required.
6 (Vincent Ladeuil, #322767, #414589)
7
8+* ``bzr help`` will no longer trigger the get_missing_command hook when
9+ doing a topic lookup. This avoids prompting (like 'no command plugins/loom,
10+ did you mean log?') when getting help. In future we may trigger the hook
11+ deliberately when no help topics match from any help index.
12+ (Robert Collins, #396261)
13+
14 * ``bzr remove-tree`` can now remove multiple working trees.
15 (Jared Hance, Andrew Bennetts, #253137)
16
17
18=== modified file 'bzrlib/commands.py'
19--- bzrlib/commands.py 2010-02-23 07:43:11 +0000
20+++ bzrlib/commands.py 2010-02-26 04:48:18 +0000
21@@ -199,11 +199,13 @@
22 raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
23
24
25-def _get_cmd_object(cmd_name, plugins_override=True):
26+def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
27 """Get a command object.
28
29 :param cmd_name: The name of the command.
30 :param plugins_override: Allow plugins to override builtins.
31+ :param check_missing: Look up commands not found in the regular index via
32+ the get_missing_command hook.
33 :return: A Command object instance
34 :raises KeyError: If no command is found.
35 """
36@@ -219,7 +221,7 @@
37 # We've found a non-plugin command, don't permit it to be
38 # overridden.
39 break
40- if cmd is None:
41+ if cmd is None and check_missing:
42 for hook in Command.hooks['get_missing_command']:
43 cmd = hook(cmd_name)
44 if cmd is not None:
45@@ -1162,7 +1164,7 @@
46 if topic and topic.startswith(self.prefix):
47 topic = topic[len(self.prefix):]
48 try:
49- cmd = _get_cmd_object(topic)
50+ cmd = _get_cmd_object(topic, check_missing=False)
51 except KeyError:
52 return []
53 else:
54
55=== modified file 'bzrlib/tests/test_commands.py'
56--- bzrlib/tests/test_commands.py 2010-01-14 13:17:33 +0000
57+++ bzrlib/tests/test_commands.py 2010-02-26 04:48:17 +0000
58@@ -276,32 +276,45 @@
59
60 class TestGetMissingCommandHook(tests.TestCase):
61
62- def test_fires_on_get_cmd_object(self):
63- # The get_missing_command(cmd) hook fires when commands are delivered to the
64- # ui.
65- hook_calls = []
66+ def hook_missing(self):
67+ """Hook get_missing_command for testing."""
68+ self.hook_calls = []
69 class ACommand(commands.Command):
70 """A sample command."""
71 def get_missing_cmd(cmd_name):
72- hook_calls.append(('called', cmd_name))
73+ self.hook_calls.append(('called', cmd_name))
74 if cmd_name in ('foo', 'info'):
75 return ACommand()
76 commands.Command.hooks.install_named_hook(
77 "get_missing_command", get_missing_cmd, None)
78+ self.ACommand = ACommand
79+
80+ def test_fires_on_get_cmd_object(self):
81+ # The get_missing_command(cmd) hook fires when commands are delivered to the
82+ # ui.
83+ self.hook_missing()
84 # create a command directly, should not fire
85- cmd = ACommand()
86- self.assertEqual([], hook_calls)
87+ self.cmd = self.ACommand()
88+ self.assertEqual([], self.hook_calls)
89 # ask by name, should fire and give us our command
90 cmd = commands.get_cmd_object('foo')
91- self.assertEqual([('called', 'foo')], hook_calls)
92- self.assertIsInstance(cmd, ACommand)
93- del hook_calls[:]
94+ self.assertEqual([('called', 'foo')], self.hook_calls)
95+ self.assertIsInstance(cmd, self.ACommand)
96+ del self.hook_calls[:]
97 # ask by a name that is supplied by a builtin - the hook should not
98 # fire and we still get our object.
99 commands.install_bzr_command_hooks()
100 cmd = commands.get_cmd_object('info')
101 self.assertNotEqual(None, cmd)
102- self.assertEqual(0, len(hook_calls))
103+ self.assertEqual(0, len(self.hook_calls))
104+
105+ def test_skipped_on_HelpCommandIndex_get_topics(self):
106+ # The get_missing_command(cmd_name) hook is not fired when
107+ # looking up help topics.
108+ self.hook_missing()
109+ topic = commands.HelpCommandIndex()
110+ topics = topic.get_topics('foo')
111+ self.assertEqual([], self.hook_calls)
112
113
114 class TestListCommandHook(tests.TestCase):