~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/doc_generate/autodoc_man.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from __future__ import absolute_import
25
25
 
 
26
PLUGINS_TO_DOCUMENT = ["launchpad"]
 
27
 
26
28
import textwrap
27
29
import time
28
30
 
31
33
import bzrlib.help_topics
32
34
import bzrlib.commands
33
35
 
 
36
from bzrlib.plugin import load_plugins
 
37
load_plugins()
 
38
 
34
39
 
35
40
def get_filename(options):
36
41
    """Provides name of manpage"""
51
56
    outfile.write(man_escape(man_head % params))
52
57
    outfile.write(man_escape(getcommand_list(params)))
53
58
    outfile.write(man_escape(getcommand_help(params)))
 
59
    outfile.write("".join(environment_variables()))
54
60
    outfile.write(man_escape(man_foot % params))
55
61
 
56
62
 
57
63
def man_escape(string):
58
64
    """Escapes strings for man page compatibility"""
59
65
    result = string.replace("\\","\\\\")
60
 
    result = result.replace("`","\\`")
61
 
    result = result.replace("'","\\'")
 
66
    result = result.replace("`","\\'")
 
67
    result = result.replace("'","\\*(Aq")
62
68
    result = result.replace("-","\\-")
63
69
    return result
64
70
 
66
72
def command_name_list():
67
73
    """Builds a list of command names from bzrlib"""
68
74
    command_names = bzrlib.commands.builtin_command_names()
 
75
    for cmdname in bzrlib.commands.plugin_command_names():
 
76
        cmd_object = bzrlib.commands.get_cmd_object(cmdname)
 
77
        if (PLUGINS_TO_DOCUMENT is None or
 
78
            cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
 
79
            command_names.append(cmdname)
69
80
    command_names.sort()
70
81
    return command_names
71
82
 
105
116
    return output
106
117
 
107
118
 
108
 
def format_command (params, cmd):
 
119
def format_command(params, cmd):
109
120
    """Provides long help for each public command"""
110
121
    subsection_header = '.SS "%s"\n' % (cmd._usage())
111
122
    doc = "%s\n" % (cmd.__doc__)
112
123
    doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
113
124
 
 
125
    # A dot at the beginning of a line is interpreted as a macro.
 
126
    # Simply join lines that begin with a dot with the previous
 
127
    # line to work around this.
 
128
    doc = doc.replace("\n.", ".")
 
129
 
114
130
    option_str = ""
115
131
    options = cmd.options()
116
132
    if options:
129
145
                    subsequent_indent=30*' ',
130
146
                    break_long_words=False,
131
147
                    )
132
 
                option_str = option_str + wrapped + '\n'       
 
148
                option_str += wrapped + '\n'
133
149
 
134
150
    aliases_str = ""
135
151
    if cmd.aliases:
156
172
    return help
157
173
 
158
174
 
 
175
def environment_variables():
 
176
    yield ".SH \"ENVIRONMENT\"\n"
 
177
 
 
178
    from bzrlib.help_topics import known_env_variables
 
179
    for k, desc in known_env_variables:
 
180
        yield ".TP\n"
 
181
        yield ".I \"%s\"\n" % k
 
182
        yield man_escape(desc) + "\n"
 
183
 
 
184
 
159
185
man_preamble = """\
160
186
.\\\"Man page for Bazaar (%(bzrcmd)s)
161
187
.\\\"
165
191
.\\\"
166
192
.\\\" Generation time: %(timestamp)s
167
193
.\\\"
 
194
 
 
195
.ie \\n(.g .ds Aq \\(aq
 
196
.el .ds Aq '
168
197
"""
169
198
 
170
199
 
197
226
"""
198
227
 
199
228
man_foot = """\
200
 
.SH "ENVIRONMENT"
201
 
.TP
202
 
.I "BZRPATH"
203
 
Path where
204
 
.B "%(bzrcmd)s"
205
 
is to look for shell plugin external commands.
206
 
.TP
207
 
.I "BZR_EMAIL"
208
 
E-Mail address of the user. Overrides default user config.
209
 
.TP
210
 
.I "EMAIL"
211
 
E-Mail address of the user. Overrides default user config.
212
 
.TP
213
 
.I "BZR_EDITOR"
214
 
Editor for editing commit messages
215
 
.TP
216
 
.I "EDITOR"
217
 
Editor for editing commit messages
218
 
.TP
219
 
.I "BZR_PLUGIN_PATH"
220
 
Paths where bzr should look for plugins
221
 
.TP
222
 
.I "BZR_HOME"
223
 
Home directory for bzr
224
229
.SH "FILES"
225
230
.TP
226
231
.I "~/.bazaar/bazaar.conf"