14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""man.py - create man page from built-in bzr help and static text
17
"""man.py - create man page from built-in brz help and static text
20
* use usage information instead of simple "bzr foo" in COMMAND OVERVIEW
20
* use usage information instead of simple "brz foo" in COMMAND OVERVIEW
21
21
* add command aliases
24
from __future__ import absolute_import
26
PLUGINS_TO_DOCUMENT = ["launchpad"]
31
import bzrlib.help_topics
32
import bzrlib.commands
32
import breezy.help_topics
33
import breezy.commands
34
from breezy.doc_generate import get_autodoc_datetime
36
from breezy.plugin import load_plugins
35
40
def get_filename(options):
36
41
"""Provides name of manpage"""
37
return "%s.1" % (options.bzr_name)
42
return "%s.1" % (options.brz_name)
40
45
def infogen(options, outfile):
41
46
"""Assembles a man page"""
47
d = get_autodoc_datetime()
45
{ "bzrcmd": options.bzr_name,
46
"datestamp": time.strftime("%Y-%m-%d",tt),
47
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
48
"version": bzrlib.__version__,
49
{"brzcmd": options.brz_name,
50
"datestamp": d.strftime("%Y-%m-%d"),
51
"timestamp": d.strftime("%Y-%m-%d %H:%M:%S +0000"),
52
"version": breezy.__version__,
50
54
outfile.write(man_preamble % params)
51
55
outfile.write(man_escape(man_head % params))
52
56
outfile.write(man_escape(getcommand_list(params)))
53
57
outfile.write(man_escape(getcommand_help(params)))
58
outfile.write("".join(environment_variables()))
54
59
outfile.write(man_escape(man_foot % params))
57
62
def man_escape(string):
58
63
"""Escapes strings for man page compatibility"""
59
result = string.replace("\\","\\\\")
60
result = result.replace("`","\\`")
61
result = result.replace("'","\\'")
62
result = result.replace("-","\\-")
64
result = string.replace("\\", "\\\\")
65
result = result.replace("`", "\\'")
66
result = result.replace("'", "\\*(Aq")
67
result = result.replace("-", "\\-")
66
71
def command_name_list():
67
"""Builds a list of command names from bzrlib"""
68
command_names = bzrlib.commands.builtin_command_names()
72
"""Builds a list of command names from breezy"""
73
command_names = breezy.commands.builtin_command_names()
74
for cmdname in breezy.commands.plugin_command_names():
75
cmd_object = breezy.commands.get_cmd_object(cmdname)
76
if (PLUGINS_TO_DOCUMENT is None or
77
cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
78
command_names.append(cmdname)
69
79
command_names.sort()
70
80
return command_names
73
def getcommand_list (params):
83
def getcommand_list(params):
74
84
"""Builds summary help for command names in manpage format"""
75
bzrcmd = params["bzrcmd"]
85
brzcmd = params["brzcmd"]
76
86
output = '.SH "COMMAND OVERVIEW"\n'
77
87
for cmd_name in command_name_list():
78
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
88
cmd_object = breezy.commands.get_cmd_object(cmd_name)
79
89
if cmd_object.hidden:
81
91
cmd_help = cmd_object.help()
85
95
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
86
96
output = output + tmp
88
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
98
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
92
102
def getcommand_help(params):
93
"""Shows individual options for a bzr command"""
94
output='.SH "COMMAND REFERENCE"\n'
103
"""Shows individual options for a brz command"""
104
output = '.SH "COMMAND REFERENCE"\n'
96
106
for cmd_name in command_name_list():
97
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
107
cmd_object = breezy.commands.get_cmd_object(cmd_name)
98
108
if cmd_object.hidden:
100
110
formatted[cmd_name] = format_command(params, cmd_object)
108
def format_command (params, cmd):
118
def format_command(params, cmd):
109
119
"""Provides long help for each public command"""
110
120
subsection_header = '.SS "%s"\n' % (cmd._usage())
111
121
doc = "%s\n" % (cmd.__doc__)
112
doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
122
doc = breezy.help_topics.help_as_plain_text(cmd.help())
124
# A dot at the beginning of a line is interpreted as a macro.
125
# Simply join lines that begin with a dot with the previous
126
# line to work around this.
127
doc = doc.replace("\n.", ".")
115
130
options = cmd.options()
153
168
def format_alias(params, alias, cmd_name):
154
help = '.SS "bzr %s"\n' % alias
155
help += 'Alias for "%s", see "bzr %s".\n' % (cmd_name, cmd_name)
169
help = '.SS "brz %s"\n' % alias
170
help += 'Alias for "%s", see "brz %s".\n' % (cmd_name, cmd_name)
174
def environment_variables():
175
yield ".SH \"ENVIRONMENT\"\n"
177
from breezy.help_topics import known_env_variables
178
for k, desc in known_env_variables:
180
yield ".I \"%s\"\n" % k
181
yield man_escape(desc) + "\n"
159
184
man_preamble = """\
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
185
.\\\"Man page for Breezy (%(brzcmd)s)
162
187
.\\\" Large parts of this file are autogenerated from the output of
163
.\\\" \"%(bzrcmd)s help commands\"
164
.\\\" \"%(bzrcmd)s help <cmd>\"
166
.\\\" Generation time: %(timestamp)s
188
.\\\" \"%(brzcmd)s help commands\"
189
.\\\" \"%(brzcmd)s help <cmd>\"
192
.ie \\n(.g .ds Aq \\(aq
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
198
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
174
%(bzrcmd)s - Bazaar next-generation distributed version control
200
%(brzcmd)s - Breezy next-generation distributed version control
179
205
.I "command_options"
188
214
.SH "DESCRIPTION"
189
Bazaar (or %(bzrcmd)s) is a project of Canonical to develop an open source
190
distributed version control system that is powerful, friendly, and scalable.
191
Version control means a system that keeps track of previous revisions
192
of software source code or similar information and helps people work on it in teams.
216
Breezy (or %(brzcmd)s) is a distributed version control system that is powerful,
217
friendly, and scalable. Breezy is a fork of the Bazaar version control system.
219
Breezy keeps track of changes to software source code (or similar information);
220
lets you explore who changed it, when, and why; merges concurrent changes; and
221
helps people work together in a team.
201
is to look for shell plugin external commands.
204
E-Mail address of the user. Overrides default user config.
207
E-Mail address of the user. Overrides default user config.
210
Editor for editing commit messages
213
Editor for editing commit messages
216
Paths where bzr should look for plugins
219
Home directory for bzr
222
.I "~/.bazaar/bazaar.conf"
227
.I "~/.config/breezy/breezy.conf"
223
228
Contains the user's default configuration. The section
225
230
is used to define general configuration that will be applied everywhere.