49
from bzrlib.hooks import HookPoint, Hooks
46
from bzrlib.hooks import Hooks
50
47
# Compatibility - Option used to be in commands.
51
48
from bzrlib.option import Option
52
49
from bzrlib.plugin import disable_plugins, load_plugins
396
396
sys.stdout is forced to be a binary stream, and line-endings
397
397
will not mangled.
400
A string indicating the real name under which this command was
401
invoked, before expansion of aliases.
402
(This may be None if the command was constructed and run in-process.)
399
404
:cvar hooks: An instance of CommandHooks.
406
:ivar __doc__: The help shown by 'bzr help command' for this command.
407
This is set by assigning explicitly to __doc__ so that -OO can
411
__doc__ = "My help goes here"
403
415
takes_options = []
404
416
encoding_type = 'strict'
408
421
def __init__(self):
409
422
"""Construct an instance of this command."""
410
if self.__doc__ == Command.__doc__:
411
warn("No help message set for %r" % self)
412
423
# List of standard options directly supported
413
424
self.supported_std_options = []
414
425
self._setup_run()
482
493
message explaining how to obtain full help.
484
495
doc = self.help()
486
raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
497
doc = "No help for this command."
488
499
# Extract the summary (purpose) and sections out from the text
489
500
purpose,sections,order = self._get_help_parts(doc)
683
694
self._setup_outf()
685
return self.run(**all_cmd_args)
697
return self.run(**all_cmd_args)
699
# reset it, so that other commands run in the same process won't
700
# inherit state. Before we reset it, log any activity, so that it
701
# gets properly tracked.
702
ui.ui_factory.log_transport_activity(
703
display=('bytes' in debug.debug_flags))
704
trace.set_verbosity_level(0)
687
706
def _setup_run(self):
688
707
"""Wrap the defined run method on self with a cleanup.
762
785
These are all empty initially, because by default nothing should get
766
self.create_hook(HookPoint('extend_command',
788
Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
789
self.add_hook('extend_command',
767
790
"Called after creating a command object to allow modifications "
768
791
"such as adding or removing options, docs etc. Called with the "
769
"new bzrlib.commands.Command object.", (1, 13), None))
770
self.create_hook(HookPoint('get_command',
792
"new bzrlib.commands.Command object.", (1, 13))
793
self.add_hook('get_command',
771
794
"Called when creating a single command. Called with "
772
795
"(cmd_or_None, command_name). get_command should either return "
773
796
"the cmd_or_None parameter, or a replacement Command object that "
774
797
"should be used for the command. Note that the Command.hooks "
775
798
"hooks are core infrastructure. Many users will prefer to use "
776
799
"bzrlib.commands.register_command or plugin_cmds.register_lazy.",
778
self.create_hook(HookPoint('get_missing_command',
801
self.add_hook('get_missing_command',
779
802
"Called when creating a single command if no command could be "
780
803
"found. Called with (command_name). get_missing_command should "
781
804
"either return None, or a Command object to be used for the "
782
"command.", (1, 17), None))
783
self.create_hook(HookPoint('list_commands',
806
self.add_hook('list_commands',
784
807
"Called when enumerating commands. Called with a set of "
785
808
"cmd_name strings for all the commands found so far. This set "
786
809
" is safe to mutate - e.g. to remove a command. "
787
810
"list_commands should return the updated set of command names.",
790
813
Command.hooks = CommandHooks()
808
options, args = parser.parse_args(args)
831
# for python 2.5 and later, optparse raises this exception if a non-ascii
832
# option name is given. See http://bugs.python.org/issue2931
834
options, args = parser.parse_args(args)
835
except UnicodeEncodeError,e:
836
raise errors.BzrCommandError('Only ASCII permitted in option names')
809
838
opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
810
839
v is not option.OptionParser.DEFAULT_VALUE])
811
840
return args, opts
1015
1044
Specify the number of processes that can be run concurrently (selftest).
1017
1046
trace.mutter("bazaar version: " + bzrlib.__version__)
1047
argv = _specified_or_unicode_argv(argv)
1019
1048
trace.mutter("bzr arguments: %r", argv)
1021
1050
opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
1077
1108
if not opt_no_aliases:
1078
1109
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]
1082
1111
argv[0] = alias_argv.pop(0)
1084
1113
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.
1089
1114
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
1090
1115
run = cmd_obj.run_argv_aliases
1091
1116
run_argv = [argv, alias_argv]
1188
1213
:return: exit code of bzr command.
1190
argv = _specified_or_unicode_argv(argv)
1215
if argv is not None:
1191
1217
_register_builtin_commands()
1192
1218
ret = run_bzr_catch_errors(argv)
1193
bzrlib.ui.ui_factory.log_transport_activity(
1194
display=('bytes' in debug.debug_flags))
1195
1219
trace.mutter("return code %d", ret)