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
397
396
sys.stdout is forced to be a binary stream, and line-endings
398
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.)
400
404
:cvar hooks: An instance of CommandHooks.
401
406
:ivar __doc__: The help shown by 'bzr help command' for this command.
402
407
This is set by assigning explicitly to __doc__ so that -OO can
514
520
# so we get <https://bugs.launchpad.net/bzr/+bug/249908>. -- mbp
516
522
options = option.get_optparser(self.options()).format_option_help()
517
# XXX: According to the spec, ReST option lists actually don't support
518
# options like --1.9 so that causes syntax errors (in Sphinx at least).
519
# As that pattern always appears in the commands that break, we trap
520
# on that and then format that block of 'format' options as a literal
522
if not plain and options.find(' --1.9 ') != -1:
523
# FIXME: According to the spec, ReST option lists actually don't
524
# support options like --1.14 so that causes syntax errors (in Sphinx
525
# at least). As that pattern always appears in the commands that
526
# break, we trap on that and then format that block of 'format' options
527
# as a literal block. We use the most recent format still listed so we
528
# don't have to do that too often -- vila 20110514
529
if not plain and options.find(' --1.14 ') != -1:
523
530
options = options.replace(' format:\n', ' format::\n\n', 1)
524
531
if options.startswith('Options:'):
525
532
result += ':' + options
688
695
self._setup_outf()
690
return self.run(**all_cmd_args)
698
return self.run(**all_cmd_args)
700
# reset it, so that other commands run in the same process won't
701
# inherit state. Before we reset it, log any activity, so that it
702
# gets properly tracked.
703
ui.ui_factory.log_transport_activity(
704
display=('bytes' in debug.debug_flags))
705
trace.set_verbosity_level(0)
692
707
def _setup_run(self):
693
708
"""Wrap the defined run method on self with a cleanup.
767
786
These are all empty initially, because by default nothing should get
771
self.create_hook(HookPoint('extend_command',
789
Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
790
self.add_hook('extend_command',
772
791
"Called after creating a command object to allow modifications "
773
792
"such as adding or removing options, docs etc. Called with the "
774
"new bzrlib.commands.Command object.", (1, 13), None))
775
self.create_hook(HookPoint('get_command',
793
"new bzrlib.commands.Command object.", (1, 13))
794
self.add_hook('get_command',
776
795
"Called when creating a single command. Called with "
777
796
"(cmd_or_None, command_name). get_command should either return "
778
797
"the cmd_or_None parameter, or a replacement Command object that "
779
798
"should be used for the command. Note that the Command.hooks "
780
799
"hooks are core infrastructure. Many users will prefer to use "
781
800
"bzrlib.commands.register_command or plugin_cmds.register_lazy.",
783
self.create_hook(HookPoint('get_missing_command',
802
self.add_hook('get_missing_command',
784
803
"Called when creating a single command if no command could be "
785
804
"found. Called with (command_name). get_missing_command should "
786
805
"either return None, or a Command object to be used for the "
787
"command.", (1, 17), None))
788
self.create_hook(HookPoint('list_commands',
807
self.add_hook('list_commands',
789
808
"Called when enumerating commands. Called with a set of "
790
809
"cmd_name strings for all the commands found so far. This set "
791
810
" is safe to mutate - e.g. to remove a command. "
792
811
"list_commands should return the updated set of command names.",
795
814
Command.hooks = CommandHooks()
813
options, args = parser.parse_args(args)
832
# for python 2.5 and later, optparse raises this exception if a non-ascii
833
# option name is given. See http://bugs.python.org/issue2931
835
options, args = parser.parse_args(args)
836
except UnicodeEncodeError,e:
837
raise errors.BzrCommandError('Only ASCII permitted in option names')
814
839
opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
815
840
v is not option.OptionParser.DEFAULT_VALUE])
816
841
return args, opts
1020
1045
Specify the number of processes that can be run concurrently (selftest).
1022
1047
trace.mutter("bazaar version: " + bzrlib.__version__)
1048
argv = _specified_or_unicode_argv(argv)
1024
1049
trace.mutter("bzr arguments: %r", argv)
1026
1051
opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = \
1189
1214
:return: exit code of bzr command.
1191
argv = _specified_or_unicode_argv(argv)
1216
if argv is not None:
1192
1218
_register_builtin_commands()
1193
1219
ret = run_bzr_catch_errors(argv)
1194
bzrlib.ui.ui_factory.log_transport_activity(
1195
display=('bytes' in debug.debug_flags))
1196
1220
trace.mutter("return code %d", ret)