52
from bzrlib import registry
54
52
from bzrlib.hooks import HookPoint, Hooks
53
# Compatibility - Option used to be in commands.
55
54
from bzrlib.option import Option
55
from bzrlib import registry
56
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
58
59
class CommandInfo(object):
182
183
return plugin_cmds.keys()
185
def _get_cmd_dict(plugins_override=True):
186
"""Return name->class mapping for all commands."""
186
@deprecated_function(deprecated_in((1, 16, 0)))
188
"""Return canonical name and class for most commands.
190
NB: This does not return all commands since the introduction of
191
command hooks, and returning the class is not sufficient to
192
get correctly setup commands, which is why it is deprecated.
194
Use 'all_command_names' + 'get_cmd_object' instead.
187
196
d = _builtin_commands()
188
197
if plugins_override:
189
198
d.update(plugin_cmds.iteritems())
193
def get_all_cmds(plugins_override=True):
194
"""Return canonical name and class for all registered commands."""
195
for k, v in _get_cmd_dict(plugins_override=plugins_override).iteritems():
199
for k, v in d.iteritems():
220
224
# in a Unicode name. In that case, they should just get a
221
225
# 'command not found' error later.
222
226
# In the future, we may actually support Unicode command names.
226
229
for hook in Command.hooks['get_command']:
231
234
if not cmd.plugin_name():
235
plugin_metadata, provider = probe_for_provider(cmd_name)
236
raise errors.CommandAvailableInPlugin(cmd_name,
237
plugin_metadata, provider)
238
except errors.NoPluginAvailable:
237
for hook in Command.hooks['get_missing_command']:
240
242
# No command found.
242
244
# Allow plugins to extend commands
250
def _try_plugin_provider(cmd_name):
251
"""Probe for a plugin provider having cmd_name."""
253
plugin_metadata, provider = probe_for_provider(cmd_name)
254
raise errors.CommandAvailableInPlugin(cmd_name,
255
plugin_metadata, provider)
256
except errors.NoPluginAvailable:
248
260
def probe_for_provider(cmd_name):
249
261
"""Look for a provider for cmd_name.
264
276
def _get_bzr_command(cmd_or_None, cmd_name):
265
277
"""Get a command from bzr's core."""
266
cmds = _get_cmd_dict(plugins_override=False)
278
cmds = _builtin_commands()
268
280
return cmds[cmd_name]()
684
696
"Called when creating a single command. Called with "
685
697
"(cmd_or_None, command_name). get_command should either return "
686
698
"the cmd_or_None parameter, or a replacement Command object that "
687
"should be used for the command.", (1, 14), None))
699
"should be used for the command.", (1, 16), None))
700
self.create_hook(HookPoint('get_missing_command',
701
"Called when creating a single command if no command could be "
702
"found. Called with (command_name). get_missing_command should "
703
"either return None, or a Command object to be used for the "
704
"command.", (1, 16), None))
688
705
self.create_hook(HookPoint('list_commands',
689
706
"Called when enumerating commands. Called with a dict of "
690
707
"cmd_name: cmd_class tuples for all the commands found "
691
708
"so far. This dict is safe to mutate - to remove a command or "
692
709
"to replace it with another (eg plugin supplied) version. "
693
710
"list_commands should return the updated dict of commands.",
695
# We currently ship default hooks to get builtin and plugin supplied
697
self.install_named_hook("list_commands", _list_bzr_commands,
699
self.install_named_hook("get_command", _get_bzr_command,
701
self.install_named_hook("get_command", _get_plugin_command,
702
"bzr plugin commands")
703
self.install_named_hook("get_command", _get_external_command,
704
"bzr external command lookup")
706
713
Command.hooks = CommandHooks()
1046
1053
return ignore_pipe
1056
def install_bzr_command_hooks():
1057
"""Install the hooks to supply bzr's own commands."""
1058
Command.hooks.install_named_hook("list_commands", _list_bzr_commands,
1060
Command.hooks.install_named_hook("get_command", _get_bzr_command,
1062
Command.hooks.install_named_hook("get_command", _get_plugin_command,
1063
"bzr plugin commands")
1064
Command.hooks.install_named_hook("get_command", _get_external_command,
1065
"bzr external command lookup")
1066
Command.hooks.install_named_hook("get_missing_command", _try_plugin_provider,
1067
"bzr plugin-provider-db check")
1049
1070
def main(argv=None):
1050
1071
"""Main entry point of command-line interface.
1063
1084
# Is this a final release version? If so, we should suppress warnings
1064
1085
if bzrlib.version_info[3] == 'final':
1065
from bzrlib import symbol_versioning
1066
1086
symbol_versioning.suppress_deprecation_warnings(override=False)
1067
1087
if argv is None:
1068
1088
argv = osutils.get_unicode_argv()
1078
1098
except UnicodeDecodeError:
1079
1099
raise errors.BzrError("argv should be list of unicode strings.")
1080
1100
argv = new_argv
1101
install_bzr_command_hooks()
1081
1102
ret = run_bzr_catch_errors(argv)
1082
1103
trace.mutter("return code %d", ret)