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
35
from breezy.doc_generate import get_autodoc_datetime
37
from breezy.plugin import load_plugins
35
41
def get_filename(options):
36
42
"""Provides name of manpage"""
37
return "%s.1" % (options.bzr_name)
43
return "%s.1" % (options.brz_name)
40
46
def infogen(options, outfile):
41
47
"""Assembles a man page"""
48
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__,
50
{ "brzcmd": options.brz_name,
51
"datestamp": d.strftime("%Y-%m-%d"),
52
"timestamp": d.strftime("%Y-%m-%d %H:%M:%S +0000"),
53
"version": breezy.__version__,
50
55
outfile.write(man_preamble % params)
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))
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("-","\\-")
66
72
def command_name_list():
67
"""Builds a list of command names from bzrlib"""
68
command_names = bzrlib.commands.builtin_command_names()
73
"""Builds a list of command names from breezy"""
74
command_names = breezy.commands.builtin_command_names()
75
for cmdname in breezy.commands.plugin_command_names():
76
cmd_object = breezy.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
73
84
def getcommand_list (params):
74
85
"""Builds summary help for command names in manpage format"""
75
bzrcmd = params["bzrcmd"]
86
brzcmd = params["brzcmd"]
76
87
output = '.SH "COMMAND OVERVIEW"\n'
77
88
for cmd_name in command_name_list():
78
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
89
cmd_object = breezy.commands.get_cmd_object(cmd_name)
79
90
if cmd_object.hidden:
81
92
cmd_help = cmd_object.help()
85
96
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
86
97
output = output + tmp
88
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
99
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
92
103
def getcommand_help(params):
93
"""Shows individual options for a bzr command"""
104
"""Shows individual options for a brz command"""
94
105
output='.SH "COMMAND REFERENCE"\n'
96
107
for cmd_name in command_name_list():
97
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
108
cmd_object = breezy.commands.get_cmd_object(cmd_name)
98
109
if cmd_object.hidden:
100
111
formatted[cmd_name] = format_command(params, cmd_object)
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
doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
123
doc = breezy.help_topics.help_as_plain_text(cmd.help())
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.", ".")
115
131
options = cmd.options()
153
169
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)
170
help = '.SS "brz %s"\n' % alias
171
help += 'Alias for "%s", see "brz %s".\n' % (cmd_name, cmd_name)
175
def environment_variables():
176
yield ".SH \"ENVIRONMENT\"\n"
178
from breezy.help_topics import known_env_variables
179
for k, desc in known_env_variables:
181
yield ".I \"%s\"\n" % k
182
yield man_escape(desc) + "\n"
159
185
man_preamble = """\
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
186
.\\\"Man page for Breezy (%(brzcmd)s)
162
188
.\\\" 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
189
.\\\" \"%(brzcmd)s help commands\"
190
.\\\" \"%(brzcmd)s help <cmd>\"
193
.ie \\n(.g .ds Aq \\(aq
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
199
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
174
%(bzrcmd)s - Bazaar next-generation distributed version control
201
%(brzcmd)s - Breezy next-generation distributed version control
179
206
.I "command_options"
188
215
.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.
217
Breezy (or %(brzcmd)s) is a distributed version control system that is powerful,
218
friendly, and scalable. Breezy is a fork of the Bazaar version control system.
220
Breezy keeps track of changes to software source code (or similar information);
221
lets you explore who changed it, when, and why; merges concurrent changes; and
222
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
228
.I "~/.bazaar/bazaar.conf"