138
138
If true, plugin commands can override builtins.
141
return _get_cmd_object(cmd_name, plugins_override)
143
raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
146
def _get_cmd_object(cmd_name, plugins_override=True):
147
"""Worker for get_cmd_object which raises KeyError rather than BzrCommandError."""
140
148
from bzrlib.externalcommand import ExternalCommand
142
150
# We want only 'ascii' command names, but the user may have typed
233
240
if self.__doc__ == Command.__doc__:
234
241
warn("No help message set for %r" % self)
244
"""Return single-line grammar for this command.
246
Only describes arguments, not options.
248
s = 'bzr ' + self.name() + ' '
249
for aname in self.takes_args:
250
aname = aname.upper()
251
if aname[-1] in ['$', '+']:
252
aname = aname[:-1] + '...'
253
elif aname[-1] == '?':
254
aname = '[' + aname[:-1] + ']'
255
elif aname[-1] == '*':
256
aname = '[' + aname[:-1] + '...]'
263
def get_help_text(self, additional_see_also=None):
264
"""Return a text string with help for this command.
266
:param additional_see_also: Additional help topics to be
271
raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
274
result += 'usage: %s\n' % self._usage()
277
result += 'aliases:\n'
278
result += ', '.join(self.aliases) + '\n'
282
plugin_name = self.plugin_name()
283
if plugin_name is not None:
284
result += '(From plugin "%s")' % plugin_name
288
if result[-1] != '\n':
291
result += option.get_optparser(self.options()).format_option_help()
292
see_also = self.get_see_also(additional_see_also)
294
result += '\nSee also: '
295
result += ', '.join(see_also)
299
def get_help_topic(self):
300
"""Return the commands help topic - its name."""
303
def get_see_also(self, additional_terms=None):
304
"""Return a list of help topics that are related to this ommand.
306
The list is derived from the content of the _see_also attribute. Any
307
duplicates are removed and the result is in lexical order.
308
:param additional_terms: Additional help topics to cross-reference.
309
:return: A list of help topics.
311
see_also = set(getattr(self, '_see_also', []))
313
see_also.update(additional_terms)
314
return sorted(see_also)
236
316
def options(self):
237
317
"""Return dict of valid options for this command.
280
360
args, opts = parse_args(self, argv, alias_argv)
281
361
if 'help' in opts: # e.g. bzr add --help
282
from bzrlib.help import help_on_command
283
help_on_command(self.name())
362
sys.stdout.write(self.get_help_text())
285
364
# mix arguments and options into one dictionary
286
365
cmdargs = _match_argform(self.name(), self.takes_args, args)
636
715
def run_bzr_catch_errors(argv):
639
# do this here inside the exception wrappers to catch EPIPE
720
# do this here inside the exception wrappers to catch EPIPE
641
722
except (KeyboardInterrupt, Exception), e:
642
723
# used to handle AssertionError and KeyboardInterrupt
643
724
# specially here, but hopefully they're handled ok by the logger now
648
729
pdb.post_mortem(sys.exc_traceback)
733
class HelpCommandIndex(object):
734
"""A index for bzr help that returns commands."""
737
self.prefix = 'commands/'
739
def get_topics(self, topic):
740
"""Search for topic amongst commands.
742
:param topic: A topic to search for.
743
:return: A list which is either empty or contains a single
746
if topic and topic.startswith(self.prefix):
747
topic = topic[len(self.prefix):]
749
cmd = _get_cmd_object(topic)
651
756
if __name__ == '__main__':
652
757
sys.exit(main(sys.argv))