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
PLUGINS_TO_DOCUMENT = ["launchpad"]
30
import breezy.help_topics
31
import breezy.commands
32
from breezy.doc_generate import get_autodoc_datetime
34
from breezy.plugin import load_plugins
31
import bzrlib.help_topics
32
import bzrlib.commands
38
35
def get_filename(options):
39
36
"""Provides name of manpage"""
40
return "%s.1" % (options.brz_name)
37
return "%s.1" % (options.bzr_name)
43
40
def infogen(options, outfile):
44
41
"""Assembles a man page"""
45
d = get_autodoc_datetime()
47
{"brzcmd": options.brz_name,
48
"datestamp": d.strftime("%Y-%m-%d"),
49
"timestamp": d.strftime("%Y-%m-%d %H:%M:%S +0000"),
50
"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__,
52
50
outfile.write(man_preamble % params)
53
51
outfile.write(man_escape(man_head % params))
54
52
outfile.write(man_escape(getcommand_list(params)))
55
53
outfile.write(man_escape(getcommand_help(params)))
56
outfile.write("".join(environment_variables()))
57
54
outfile.write(man_escape(man_foot % params))
60
57
def man_escape(string):
61
58
"""Escapes strings for man page compatibility"""
62
result = string.replace("\\", "\\\\")
63
result = result.replace("`", "\\'")
64
result = result.replace("'", "\\*(Aq")
65
result = result.replace("-", "\\-")
59
result = string.replace("\\","\\\\")
60
result = result.replace("`","\\`")
61
result = result.replace("'","\\'")
62
result = result.replace("-","\\-")
69
66
def command_name_list():
70
"""Builds a list of command names from breezy"""
71
command_names = breezy.commands.builtin_command_names()
72
for cmdname in breezy.commands.plugin_command_names():
73
cmd_object = breezy.commands.get_cmd_object(cmdname)
74
if (PLUGINS_TO_DOCUMENT is None or
75
cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
76
command_names.append(cmdname)
67
"""Builds a list of command names from bzrlib"""
68
command_names = bzrlib.commands.builtin_command_names()
77
69
command_names.sort()
78
70
return command_names
81
def getcommand_list(params):
73
def getcommand_list (params):
82
74
"""Builds summary help for command names in manpage format"""
83
brzcmd = params["brzcmd"]
75
bzrcmd = params["bzrcmd"]
84
76
output = '.SH "COMMAND OVERVIEW"\n'
85
77
for cmd_name in command_name_list():
86
cmd_object = breezy.commands.get_cmd_object(cmd_name)
78
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
87
79
if cmd_object.hidden:
89
81
cmd_help = cmd_object.help()
93
85
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
94
86
output = output + tmp
96
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
88
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
100
92
def getcommand_help(params):
101
"""Shows individual options for a brz command"""
102
output = '.SH "COMMAND REFERENCE"\n'
93
"""Shows individual options for a bzr command"""
94
output='.SH "COMMAND REFERENCE"\n'
104
96
for cmd_name in command_name_list():
105
cmd_object = breezy.commands.get_cmd_object(cmd_name)
97
cmd_object = bzrlib.commands.get_cmd_object(cmd_name)
106
98
if cmd_object.hidden:
108
100
formatted[cmd_name] = format_command(params, cmd_object)
116
def format_command(params, cmd):
108
def format_command (params, cmd):
117
109
"""Provides long help for each public command"""
118
110
subsection_header = '.SS "%s"\n' % (cmd._usage())
119
111
doc = "%s\n" % (cmd.__doc__)
120
doc = breezy.help_topics.help_as_plain_text(cmd.help())
122
# A dot at the beginning of a line is interpreted as a macro.
123
# Simply join lines that begin with a dot with the previous
124
# line to work around this.
125
doc = doc.replace("\n.", ".")
112
doc = bzrlib.help_topics.help_as_plain_text(cmd.help())
128
115
options = cmd.options()
166
153
def format_alias(params, alias, cmd_name):
167
help = '.SS "brz %s"\n' % alias
168
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)
172
def environment_variables():
173
yield ".SH \"ENVIRONMENT\"\n"
175
from breezy.help_topics import known_env_variables
176
for k, desc in known_env_variables:
178
yield ".I \"%s\"\n" % k
179
yield man_escape(desc) + "\n"
182
159
man_preamble = """\
183
.\\\"Man page for Breezy (%(brzcmd)s)
160
.\\\"Man page for Bazaar (%(bzrcmd)s)
185
162
.\\\" Large parts of this file are autogenerated from the output of
186
.\\\" \"%(brzcmd)s help commands\"
187
.\\\" \"%(brzcmd)s help <cmd>\"
190
.ie \\n(.g .ds Aq \\(aq
163
.\\\" \"%(bzrcmd)s help commands\"
164
.\\\" \"%(bzrcmd)s help <cmd>\"
166
.\\\" Generation time: %(timestamp)s
196
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
172
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
198
%(brzcmd)s - Breezy next-generation distributed version control
174
%(bzrcmd)s - Bazaar next-generation distributed version control
203
179
.I "command_options"
212
188
.SH "DESCRIPTION"
214
Breezy (or %(brzcmd)s) is a distributed version control system that is powerful,
215
friendly, and scalable. Breezy is a fork of the Bazaar version control system.
190
Bazaar (or %(bzrcmd)s) is a distributed version control system that is powerful,
191
friendly, and scalable. Bazaar is a project of Canonical Ltd and part of
192
the GNU Project to develop a free operating system.
217
Breezy keeps track of changes to software source code (or similar information);
194
Bazaar keeps track of changes to software source code (or similar information);
218
195
lets you explore who changed it, when, and why; merges concurrent changes; and
219
196
helps people work together in a team.
205
is to look for shell plugin external commands.
208
E-Mail address of the user. Overrides default user config.
211
E-Mail address of the user. Overrides default user config.
214
Editor for editing commit messages
217
Editor for editing commit messages
220
Paths where bzr should look for plugins
223
Home directory for bzr
225
.I "~/.config/breezy/breezy.conf"
226
.I "~/.bazaar/bazaar.conf"
226
227
Contains the user's default configuration. The section
228
229
is used to define general configuration that will be applied everywhere.