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 brz help and static text
17
"""man.py - create man page from built-in bzr help and static text
20
* use usage information instead of simple "brz foo" in COMMAND OVERVIEW
20
* use usage information instead of simple "bzr foo" in COMMAND OVERVIEW
21
21
* add command aliases
24
from __future__ import absolute_import
26
PLUGINS_TO_DOCUMENT = ["launchpad"]
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
31
import bzrlib.help_topics
32
import bzrlib.commands
40
35
def get_filename(options):
41
36
"""Provides name of manpage"""
42
return "%s.1" % (options.brz_name)
37
return "%s.1" % (options.bzr_name)
45
40
def infogen(options, outfile):
46
41
"""Assembles a man page"""
47
d = get_autodoc_datetime()
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__,
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__,
54
50
outfile.write(man_preamble % params)
55
51
outfile.write(man_escape(man_head % params))
56
52
outfile.write(man_escape(getcommand_list(params)))
57
53
outfile.write(man_escape(getcommand_help(params)))
58
outfile.write("".join(environment_variables()))
59
54
outfile.write(man_escape(man_foot % params))
62
57
def man_escape(string):
63
58
"""Escapes strings for man page compatibility"""
64
result = string.replace("\\", "\\\\")
65
result = result.replace("`", "\\'")
66
result = result.replace("'", "\\*(Aq")
67
result = result.replace("-", "\\-")
59
result = string.replace("\\","\\\\")
60
result = result.replace("`","\\`")
61
result = result.replace("'","\\'")
62
result = result.replace("-","\\-")
71
66
def command_name_list():
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)
67
"""Builds a list of command names from bzrlib"""
68
command_names = bzrlib.commands.builtin_command_names()
79
69
command_names.sort()
80
70
return command_names
83
def getcommand_list(params):
73
def getcommand_list (params):
84
74
"""Builds summary help for command names in manpage format"""
85
brzcmd = params["brzcmd"]
75
bzrcmd = params["bzrcmd"]
86
76
output = '.SH "COMMAND OVERVIEW"\n'
87
77
for cmd_name in command_name_list():
88
cmd_object = breezy.commands.get_cmd_object(cmd_name)
78
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
89
79
if cmd_object.hidden:
91
81
cmd_help = cmd_object.help()
95
85
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
96
86
output = output + tmp
98
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
88
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
102
92
def getcommand_help(params):
103
"""Shows individual options for a brz command"""
104
output = '.SH "COMMAND REFERENCE"\n'
93
"""Shows individual options for a bzr command"""
94
output='.SH "COMMAND REFERENCE"\n'
106
96
for cmd_name in command_name_list():
107
cmd_object = breezy.commands.get_cmd_object(cmd_name)
97
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
108
98
if cmd_object.hidden:
110
100
formatted[cmd_name] = format_command(params, cmd_object)
118
def format_command(params, cmd):
108
def format_command (params, cmd):
119
109
"""Provides long help for each public command"""
120
110
subsection_header = '.SS "%s"\n' % (cmd._usage())
121
111
doc = "%s\n" % (cmd.__doc__)
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.", ".")
112
doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
130
115
options = cmd.options()
168
153
def format_alias(params, alias, cmd_name):
169
help = '.SS "brz %s"\n' % alias
170
help += 'Alias for "%s", see "brz %s".\n' % (cmd_name, cmd_name)
154
help = '.SS "bzr %s"\n' % alias
155
help += 'Alias for "%s", see "bzr %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"
184
159
man_preamble = """\
185
.\\\"Man page for Breezy (%(brzcmd)s)
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
187
162
.\\\" Large parts of this file are autogenerated from the output of
188
.\\\" \"%(brzcmd)s help commands\"
189
.\\\" \"%(brzcmd)s help <cmd>\"
192
.ie \\n(.g .ds Aq \\(aq
163
.\\\" \"%(bzrcmd)s help commands\"
164
.\\\" \"%(bzrcmd)s help <cmd>\"
166
.\\\" Generation time: %(timestamp)s
198
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
200
%(brzcmd)s - Breezy next-generation distributed version control
174
%(bzrcmd)s - Bazaar next-generation distributed version control
205
179
.I "command_options"
214
188
.SH "DESCRIPTION"
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.
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.
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
227
.I "~/.config/breezy/breezy.conf"
222
.I "~/.bazaar/bazaar.conf"
228
223
Contains the user's default configuration. The section
230
225
is used to define general configuration that will be applied everywhere.