49
from bzrlib.hooks import Hooks
49
from bzrlib.hooks import HookPoint, Hooks
50
50
# Compatibility - Option used to be in commands.
51
51
from bzrlib.option import Option
52
52
from bzrlib.plugin import disable_plugins, load_plugins
415
408
def __init__(self):
416
409
"""Construct an instance of this command."""
410
if self.__doc__ == Command.__doc__:
411
warn("No help message set for %r" % self)
417
412
# List of standard options directly supported
418
413
self.supported_std_options = []
419
414
self._setup_run()
487
482
message explaining how to obtain full help.
489
484
doc = self.help()
491
doc = "No help for this command."
486
raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
493
488
# Extract the summary (purpose) and sections out from the text
494
489
purpose,sections,order = self._get_help_parts(doc)
688
683
self._setup_outf()
691
return self.run(**all_cmd_args)
693
# reset it, so that other commands run in the same process won't
694
# inherit state. Before we reset it, log any activity, so that it
695
# gets properly tracked.
696
ui.ui_factory.log_transport_activity(
697
display=('bytes' in debug.debug_flags))
698
trace.set_verbosity_level(0)
685
return self.run(**all_cmd_args)
700
687
def _setup_run(self):
701
688
"""Wrap the defined run method on self with a cleanup.
775
762
These are all empty initially, because by default nothing should get
778
Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
779
self.add_hook('extend_command',
766
self.create_hook(HookPoint('extend_command',
780
767
"Called after creating a command object to allow modifications "
781
768
"such as adding or removing options, docs etc. Called with the "
782
"new bzrlib.commands.Command object.", (1, 13))
783
self.add_hook('get_command',
769
"new bzrlib.commands.Command object.", (1, 13), None))
770
self.create_hook(HookPoint('get_command',
784
771
"Called when creating a single command. Called with "
785
772
"(cmd_or_None, command_name). get_command should either return "
786
773
"the cmd_or_None parameter, or a replacement Command object that "
787
774
"should be used for the command. Note that the Command.hooks "
788
775
"hooks are core infrastructure. Many users will prefer to use "
789
776
"bzrlib.commands.register_command or plugin_cmds.register_lazy.",
791
self.add_hook('get_missing_command',
778
self.create_hook(HookPoint('get_missing_command',
792
779
"Called when creating a single command if no command could be "
793
780
"found. Called with (command_name). get_missing_command should "
794
781
"either return None, or a Command object to be used for the "
796
self.add_hook('list_commands',
782
"command.", (1, 17), None))
783
self.create_hook(HookPoint('list_commands',
797
784
"Called when enumerating commands. Called with a set of "
798
785
"cmd_name strings for all the commands found so far. This set "
799
786
" is safe to mutate - e.g. to remove a command. "
800
787
"list_commands should return the updated set of command names.",
803
790
Command.hooks = CommandHooks()
821
# for python 2.5 and later, optparse raises this exception if a non-ascii
822
# option name is given. See http://bugs.python.org/issue2931
824
options, args = parser.parse_args(args)
825
except UnicodeEncodeError,e:
826
raise errors.BzrCommandError('Only ASCII permitted in option names')
808
options, args = parser.parse_args(args)
828
809
opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
829
810
v is not option.OptionParser.DEFAULT_VALUE])
830
811
return args, opts
1098
1077
if not opt_no_aliases:
1099
1078
alias_argv = get_alias(argv[0])
1080
user_encoding = osutils.get_user_encoding()
1081
alias_argv = [a.decode(user_encoding) for a in alias_argv]
1101
1082
argv[0] = alias_argv.pop(0)
1103
1084
cmd = argv.pop(0)
1085
# We want only 'ascii' command names, but the user may have typed
1086
# in a Unicode name. In that case, they should just get a
1087
# 'command not found' error later.
1104
1089
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
1105
1090
run = cmd_obj.run_argv_aliases
1106
1091
run_argv = [argv, alias_argv]
1205
1190
argv = _specified_or_unicode_argv(argv)
1206
1191
_register_builtin_commands()
1207
1192
ret = run_bzr_catch_errors(argv)
1193
bzrlib.ui.ui_factory.log_transport_activity(
1194
display=('bytes' in debug.debug_flags))
1208
1195
trace.mutter("return code %d", ret)