349
357
summary, then a complete description of the command. A grammar
350
358
description will be inserted.
352
:cvar aliases: Other accepted names for this command.
354
:cvar takes_args: List of argument forms, marked with whether they are
355
optional, repeated, etc. Examples::
357
['to_location', 'from_branch?', 'file*']
359
* 'to_location' is required
360
* 'from_branch' is optional
361
* 'file' can be specified 0 or more times
363
:cvar takes_options: List of options that may be given for this command.
364
These can be either strings, referring to globally-defined options, or
365
option objects. Retrieve through options().
367
:cvar hidden: If true, this command isn't advertised. This is typically
361
Other accepted names for this command.
364
List of argument forms, marked with whether they are optional,
369
['to_location', 'from_branch?', 'file*']
371
'to_location' is required
372
'from_branch' is optional
373
'file' can be specified 0 or more times
376
List of options that may be given for this command. These can
377
be either strings, referring to globally-defined options,
378
or option objects. Retrieve through options().
381
If true, this command isn't advertised. This is typically
368
382
for commands intended for expert users.
370
:cvar encoding_type: Command objects will get a 'outf' attribute, which has
371
been setup to properly handle encoding of unicode strings.
372
encoding_type determines what will happen when characters cannot be
375
* strict - abort if we cannot decode
376
* replace - put in a bogus character (typically '?')
377
* exact - do not encode sys.stdout
379
NOTE: by default on Windows, sys.stdout is opened as a text stream,
380
therefore LF line-endings are converted to CRLF. When a command uses
381
encoding_type = 'exact', then sys.stdout is forced to be a binary
382
stream, and line-endings will not mangled.
385
Command objects will get a 'outf' attribute, which has been
386
setup to properly handle encoding of unicode strings.
387
encoding_type determines what will happen when characters cannot
389
strict - abort if we cannot decode
390
replace - put in a bogus character (typically '?')
391
exact - do not encode sys.stdout
393
NOTE: by default on Windows, sys.stdout is opened as a text
394
stream, therefore LF line-endings are converted to CRLF.
395
When a command uses encoding_type = 'exact', then
396
sys.stdout is forced to be a binary stream, and line-endings
385
400
A string indicating the real name under which this command was
386
invoked, before expansion of aliases.
401
invoked, before expansion of aliases.
387
402
(This may be None if the command was constructed and run in-process.)
389
404
:cvar hooks: An instance of CommandHooks.
391
:cvar __doc__: The help shown by 'bzr help command' for this command.
406
:ivar __doc__: The help shown by 'bzr help command' for this command.
392
407
This is set by assigning explicitly to __doc__ so that -OO can
396
__doc__ = "My help goes here"
411
__doc__ = "My help goes here"
400
415
takes_options = []
401
416
encoding_type = 'strict'
402
417
invoked_as = None
465
492
usage help (e.g. Purpose, Usage, Options) with a
466
493
message explaining how to obtain full help.
468
if self.l10n and not i18n.installed():
469
i18n.install() # Install i18n only for get_help_text for now.
470
495
doc = self.help()
472
# Note: If self.gettext() translates ':Usage:\n', the section will
473
# be shown after "Description" section and we don't want to
474
# translate the usage string.
475
# Though, bzr export-pot don't exports :Usage: section and it must
477
doc = self.gettext(doc)
479
doc = gettext("No help for this command.")
497
doc = "No help for this command."
481
499
# Extract the summary (purpose) and sections out from the text
482
500
purpose,sections,order = self._get_help_parts(doc)
501
519
# XXX: optparse implicitly rewraps the help, and not always perfectly,
502
520
# so we get <https://bugs.launchpad.net/bzr/+bug/249908>. -- mbp
504
parser = option.get_optparser(self.options())
505
options = parser.format_option_help()
506
# FIXME: According to the spec, ReST option lists actually don't
507
# support options like --1.14 so that causes syntax errors (in Sphinx
508
# at least). As that pattern always appears in the commands that
509
# break, we trap on that and then format that block of 'format' options
510
# as a literal block. We use the most recent format still listed so we
511
# don't have to do that too often -- vila 20110514
512
if not plain and options.find(' --1.14 ') != -1:
522
options = option.get_optparser(self.options()).format_option_help()
523
# XXX: According to the spec, ReST option lists actually don't support
524
# options like --1.9 so that causes syntax errors (in Sphinx at least).
525
# As that pattern always appears in the commands that break, we trap
526
# on that and then format that block of 'format' options as a literal
528
if not plain and options.find(' --1.9 ') != -1:
513
529
options = options.replace(' format:\n', ' format::\n\n', 1)
514
530
if options.startswith('Options:'):
515
result += gettext(':Options:%s') % (options[len('options:'):],)
531
result += ':' + options
532
elif options.startswith('options:'):
533
# Python 2.4 version of optparse
534
result += ':Options:' + options[len('options:'):]
517
536
result += options
523
542
if sections.has_key(None):
524
543
text = sections.pop(None)
525
544
text = '\n '.join(text.splitlines())
526
result += gettext(':Description:\n %s\n\n') % (text,)
545
result += ':%s:\n %s\n\n' % ('Description',text)
528
547
# Add the custom sections (e.g. Examples). Note that there's no need
529
548
# to indent these as they must be indented already in the source.
531
550
for label in order:
532
if label in sections:
533
result += ':%s:\n%s\n' % (label, sections[label])
551
if sections.has_key(label):
552
result += ':%s:\n%s\n' % (label,sections[label])
536
result += (gettext("See bzr help %s for more details and examples.\n\n")
555
result += ("See bzr help %s for more details and examples.\n\n"
539
558
# Add the aliases, source (plug-in) and see also links, if any
541
result += gettext(':Aliases: ')
560
result += ':Aliases: '
542
561
result += ', '.join(self.aliases) + '\n'
543
562
plugin_name = self.plugin_name()
544
563
if plugin_name is not None:
545
result += gettext(':From: plugin "%s"\n') % plugin_name
564
result += ':From: plugin "%s"\n' % plugin_name
546
565
see_also = self.get_see_also(additional_see_also)
548
567
if not plain and see_also_as_links:
554
573
see_also_links.append(item)
556
575
# Use a Sphinx link for this entry
557
link_text = gettext(":doc:`%s <%s-help>`") % (item, item)
576
link_text = ":doc:`%s <%s-help>`" % (item, item)
558
577
see_also_links.append(link_text)
559
578
see_also = see_also_links
560
result += gettext(':See also: %s') % ', '.join(see_also) + '\n'
579
result += ':See also: '
580
result += ', '.join(see_also) + '\n'
562
582
# If this will be rendered as plain text, convert it
644
664
def run_argv_aliases(self, argv, alias_argv=None):
645
665
"""Parse the command line and run with extra aliases in alias_argv."""
646
666
args, opts = parse_args(self, argv, alias_argv)
649
668
# Process the standard options
650
669
if 'help' in opts: # e.g. bzr add --help
651
self.outf.write(self.get_help_text())
670
sys.stdout.write(self.get_help_text())
653
672
if 'usage' in opts: # e.g. bzr add --usage
654
self.outf.write(self.get_help_text(verbose=False))
673
sys.stdout.write(self.get_help_text(verbose=False))
656
675
trace.set_verbosity_level(option._verbosity_level)
657
676
if 'verbose' in self.supported_std_options:
1258
1276
class Provider(object):
1259
"""Generic class to be overriden by plugins"""
1277
'''Generic class to be overriden by plugins'''
1261
1279
def plugin_for_command(self, cmd_name):
1262
"""Takes a command and returns the information for that plugin
1280
'''Takes a command and returns the information for that plugin
1264
1282
:return: A dictionary with all the available information
1265
for the requested plugin
1283
for the requested plugin
1267
1285
raise NotImplementedError
1270
1288
class ProvidersRegistry(registry.Registry):
1271
"""This registry exists to allow other providers to exist"""
1289
'''This registry exists to allow other providers to exist'''
1273
1291
def __iter__(self):
1274
1292
for key, provider in self.iteritems():