19
19
Help topics are meant to be help for items that aren't commands, but will
20
20
help bzr become fully learnable without referring to a tutorial.
22
Limited formatting of help text is permitted to make the text useful
23
both within the reference manual (reStructuredText) and on the screen.
24
The help text should be reStructuredText with formatting kept to a
25
minimum and, in particular, no headings. The onscreen renderer applies
26
the following simple rules before rendering the text:
28
1. A '::' appearing on the end of a line is replaced with ':'.
29
2. Lines starting with a ':' have it stripped.
31
These rules mean that literal blocks and field lists respectively can
32
be used in the help text, producing sensible input to a manual while
33
rendering on the screen naturally.
23
36
from bzrlib import registry
39
# Section identifiers (map topics to the right place in the manual)
40
SECT_COMMAND = "command"
41
SECT_CONCEPT = "concept"
42
SECT_HIDDEN = "hidden"
44
SECT_PLUGIN = "plugin"
26
47
class HelpTopicRegistry(registry.Registry):
27
48
"""A Registry customized for handling help topics."""
29
def register(self, topic, detail, summary):
50
def register(self, topic, detail, summary, section=SECT_LIST):
30
51
"""Register a new help topic.
32
53
:param topic: Name of documentation entry
33
54
:param detail: Function or string object providing detailed
34
55
documentation for topic. Function interface is detail(topic).
35
56
This should return a text string of the detailed information.
57
See the module documentation for details on help text formatting.
36
58
:param summary: String providing single-line documentation for topic.
59
:param section: Section in reference manual - see SECT_* identifiers.
38
# The detail is stored as the 'object' and the
39
super(HelpTopicRegistry, self).register(topic, detail, info=summary)
61
# The detail is stored as the 'object' and the metadata as the info
62
info=(summary,section)
63
super(HelpTopicRegistry, self).register(topic, detail, info=info)
41
def register_lazy(self, topic, module_name, member_name, summary):
65
def register_lazy(self, topic, module_name, member_name, summary,
42
67
"""Register a new help topic, and import the details on demand.
44
69
:param topic: Name of documentation entry
45
70
:param module_name: The module to find the detailed help.
46
71
:param member_name: The member of the module to use for detailed help.
47
72
:param summary: String providing single-line documentation for topic.
73
:param section: Section in reference manual - see SECT_* identifiers.
75
# The detail is stored as the 'object' and the metadata as the info
76
info=(summary,section)
49
77
super(HelpTopicRegistry, self).register_lazy(topic, module_name,
50
member_name, info=summary)
78
member_name, info=info)
52
80
def get_detail(self, topic):
53
81
"""Get the detailed help on a given topic."""
60
88
def get_summary(self, topic):
61
89
"""Get the single line summary for the topic."""
62
return self.get_info(topic)
90
info = self.get_info(topic)
96
def get_section(self, topic):
97
"""Get the section for the topic."""
98
info = self.get_info(topic)
104
def get_topics_for_section(self, section):
105
"""Get the set of topics in a section."""
107
for topic in self.keys():
108
if section == self.get_section(topic):
65
113
topic_registry = HelpTopicRegistry()
83
131
def _help_on_revisionspec(name):
84
"""Write the summary help for all documented topics to outfile."""
132
"""Generate the help for revision specs."""
85
134
import bzrlib.revisionspec
88
out.append("\nRevision prefix specifier:"
89
"\n--------------------------\n")
137
out.append("Revision Identifiers\n")
138
out.append("A revision, or a range bound, can be one of the following.\n")
140
details.append("\nFurther details are given below.\n")
142
# The help text is indented 4 spaces - this re cleans that up below
143
indent_re = re.compile(r'^ ', re.MULTILINE)
91
144
for i in bzrlib.revisionspec.SPEC_TYPES:
93
146
if doc == bzrlib.revisionspec.RevisionSpec.help_txt:
95
while (doc[-2:] == '\n\n' or doc[-1:] == ' '):
98
out.append(" %s %s\n\n" % (i.prefix, doc))
150
# Extract out the top line summary from the body and
151
# clean-up the unwanted whitespace
152
summary,doc = doc.split("\n", 1)
153
#doc = indent_re.sub('', doc)
154
while (doc[-2:] == '\n\n' or doc[-1:] == ' '):
157
# Note: The leading : here are HACKs to get reStructuredText
158
# 'field' formatting - we know that the prefix ends in a ':'.
159
out.append(":%s\n\t%s" % (i.prefix, summary))
160
details.append(":%s\n%s" % (i.prefix, doc))
162
return '\n'.join(out + details)
103
165
def _help_on_transport(name):
132
193
if not shorthelp:
134
195
if proto.endswith("://"):
135
protl.extend(add_string(proto, shorthelp, 79))
196
protl.append(add_string(proto, shorthelp, 79))
137
decl.extend(add_string(proto, shorthelp, 79))
140
out = "\nSupported URL prefix\n--------------------\n" + \
198
decl.append(add_string(proto, shorthelp, 79))
201
out = "URL Identifiers\n\n" + \
202
"Supported URL prefixes::\n\n " + \
144
out += "\nSupported modifiers\n-------------------\n" + \
206
out += "\nSupported modifiers::\n\n " + \
151
213
"""Bazaar -- a free distributed version-control tool
152
214
http://bazaar-vcs.org/
382
447
C File has conflicts
383
448
P Entry for a pending merge (not a file)
450
Column 2 - contents::
388
454
K File kind changed
392
459
* The execute bit was changed
464
"""Environment Variables
466
:BZRPATH: Path where bzr is to look for shell plugin external commands
467
:BZR_EMAIL: E-Mail address of the user. Overrides default user config.
468
:EMAIL: E-Mail address of the user. Overrides default user config.
469
:BZR_EDITOR: Editor for editing commit messages
470
:EDITOR: Editor for editing commit messages
471
:BZR_PLUGIN_PATH: Paths where bzr should look for plugins
472
:BZR_HOME: Home directory for bzr
479
:On Linux: ~/.bazaar/bazaar.conf
480
:On Windows: C:\\Documents and Settings\\username\\Application Data\\bazaar\\2.0\\bazaar.conf
482
Contains the user's default configuration. The section ``[DEFAULT]`` is
483
used to define general configuration that will be applied everywhere.
484
The section ``[ALIASES]`` can be used to create command aliases for
485
commonly used options.
487
A typical config file might look something like::
490
email=John Doe <jdoe@isp.com>
493
commit = commit --strict
494
log10 = log --short -r -10..-1
396
498
topic_registry.register("revisionspec", _help_on_revisionspec,
397
499
"Explain how to use --revision")
398
topic_registry.register('basic', _basic_help, "Basic commands")
399
topic_registry.register('topics', _help_on_topics, "Topics list")
500
topic_registry.register('basic', _basic_help, "Basic commands", SECT_HIDDEN)
501
topic_registry.register('topics', _help_on_topics, "Topics list", SECT_HIDDEN)
400
502
def get_format_topic(topic):
401
503
from bzrlib import bzrdir
402
return bzrdir.format_registry.help_topic(topic)
504
return "Storage Formats\n\n" + bzrdir.format_registry.help_topic(topic)
403
505
topic_registry.register('formats', get_format_topic, 'Directory formats')
404
506
topic_registry.register('global-options', _global_options,
405
507
'Options that can be used with any command')
406
508
topic_registry.register('checkouts', _checkouts,
407
'Information on what a checkout is')
509
'Information on what a checkout is', SECT_CONCEPT)
408
510
topic_registry.register('urlspec', _help_on_transport,
409
511
"Supported transport protocols")
410
512
topic_registry.register('status-flags', _status_flags,
411
513
"Help on status flags")
412
514
def get_bugs_topic(topic):
413
515
from bzrlib import bugtracker
414
return bugtracker.tracker_registry.help_topic(topic)
516
return "Bug Trackers\n\n" + bugtracker.tracker_registry.help_topic(topic)
415
517
topic_registry.register('bugs', get_bugs_topic, 'Bug tracker support')
416
518
topic_registry.register('repositories', _repositories,
417
'Basic information on shared repositories.')
519
'Basic information on shared repositories.',
418
521
topic_registry.register('working-trees', _working_trees,
419
'Information on working trees')
522
'Information on working trees', SECT_CONCEPT)
523
topic_registry.register('env-variables', _env_variables,
524
'Environment variable names and values')
525
topic_registry.register('files', _files,
526
'Information on configuration and log files')
422
529
class HelpTopicIndex(object):