20
20
help bzr become fully learnable without referring to a tutorial.
29
def add_topic(topic, detail, summary):
30
"""Add documentation for a new topic.
32
:param topic: Name of documentation entry.
33
:param detail: Function or string object providing detailed
34
documentation for topic. Function interface is detail(topic, outfile).
35
:param summary: String providing single-line documentation for topic.
38
_HELP_TOPICS[topic]=(detail, summary)
40
def write_topic(topic, outfile=sys.stdout):
41
"""write to outfile the topic named "name"""
42
obj, comment = _HELP_TOPICS[topic]
50
"""is "name" a topic ?"""
51
return name in _HELP_TOPICS.keys( )
54
def get_topics_list( ):
55
"""return a dict like {topic_name:topi_comment}"""
56
return _HELP_TOPICS.keys( )
58
def get_topic_summary(topic):
59
"""return the topic summary"""
60
obj, summary = _HELP_TOPICS[topic]
23
from bzrlib import registry
26
class HelpTopicRegistry(registry.Registry):
27
"""A Regsitry customized for handling help topics."""
29
def register(self, topic, detail, summary):
30
"""Register a new help topic.
32
:param topic: Name of documentation entry
33
:param detail: Function or string object providing detailed
34
documentation for topic. Function interface is detail(topic).
35
This should return a text string of the detailed information.
36
:param summary: String providing single-line documentation for topic.
38
# The detail is stored as the 'object' and the
39
super(HelpTopicRegistry, self).register(topic, detail, info=summary)
41
def register_lazy(self, topic, module_name, member_name, summary):
42
"""Register a new help topic, and import the details on demand.
44
:param topic: Name of documentation entry
45
:param module_name: The module to find the detailed help.
46
:param member_name: The member of the module to use for detailed help.
47
:param summary: String providing single-line documentation for topic.
49
super(HelpTopicRegistry, self).register(topic, module_name,
50
member_name, info=summary)
52
def get_detail(self, topic):
53
"""Get the detailed help on a given topic."""
60
def get_summary(self, topic):
61
"""Get the single line summary for the topic."""
62
return self.get_info(topic)
65
topic_registry = HelpTopicRegistry()
67
68
#----------------------------------------------------
69
def _help_on_topics(dummy, outfile):
70
def _help_on_topics(dummy):
70
71
"""Write out the help for topics to outfile"""
72
topics = get_topics_list()
73
topics = topic_registry.keys()
73
74
lmax = max(len(topic) for topic in topics)
75
77
for topic in topics:
76
summary = get_topic_summary(topic)
77
spaces = " " * (lmax-len(topic))
78
outfile.write("%s%s %s\n" % (topic, spaces, summary))
81
def _help_on_revisionspec(name, outfile):
78
summary = topic_registry.get_summary(topic)
79
out.append("%-*s %s\n" % (lmax, topic, summary))
83
def _help_on_revisionspec(name):
82
84
""""Write the summary help for all documented topics to outfile."""
83
85
import bzrlib.revisionspec
85
outfile.write("\nRevision prefix specifier:"
86
"\n--------------------------\n")
88
out.append("\nRevision prefix specifier:"
89
"\n--------------------------\n")
88
91
for i in bzrlib.revisionspec.SPEC_TYPES:
126
add_topic("revisionspec", _help_on_revisionspec, "Revisions specifier")
127
add_topic("basic", _basic_help, "Basic commands")
128
add_topic("topics", _help_on_topics, "Topics list")
131
topic_registry.register("revisionspec", _help_on_revisionspec,
132
"Explain how to use --revision")
133
topic_registry.register('basic', _basic_help, "Basic commands")
134
topic_registry.register('topics', _help_on_topics, "Topics list")