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
24
26
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
33
import brzlib.help_topics
34
import brzlib.commands
37
from brzlib.plugin import load_plugins
38
41
def get_filename(options):
39
42
"""Provides name of manpage"""
40
return "%s.1" % (options.brz_name)
43
return "%s.1" % (options.bzr_name)
43
46
def infogen(options, outfile):
44
47
"""Assembles a man page"""
45
d = get_autodoc_datetime()
48
tt = brzlib.osutils.gmtime()
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__,
50
{ "bzrcmd": options.bzr_name,
51
"datestamp": time.strftime("%Y-%m-%d",tt),
52
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S +0000",tt),
53
"version": brzlib.__version__,
52
55
outfile.write(man_preamble % params)
53
56
outfile.write(man_escape(man_head % params))
54
57
outfile.write(man_escape(getcommand_list(params)))
60
63
def man_escape(string):
61
64
"""Escapes strings for man page compatibility"""
62
result = string.replace("\\", "\\\\")
63
result = result.replace("`", "\\'")
64
result = result.replace("'", "\\*(Aq")
65
result = result.replace("-", "\\-")
65
result = string.replace("\\","\\\\")
66
result = result.replace("`","\\'")
67
result = result.replace("'","\\*(Aq")
68
result = result.replace("-","\\-")
69
72
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)
73
"""Builds a list of command names from brzlib"""
74
command_names = brzlib.commands.builtin_command_names()
75
for cmdname in brzlib.commands.plugin_command_names():
76
cmd_object = brzlib.commands.get_cmd_object(cmdname)
74
77
if (PLUGINS_TO_DOCUMENT is None or
75
cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
78
cmd_object.plugin_name() in PLUGINS_TO_DOCUMENT):
76
79
command_names.append(cmdname)
77
80
command_names.sort()
78
81
return command_names
81
def getcommand_list(params):
84
def getcommand_list (params):
82
85
"""Builds summary help for command names in manpage format"""
83
brzcmd = params["brzcmd"]
86
bzrcmd = params["bzrcmd"]
84
87
output = '.SH "COMMAND OVERVIEW"\n'
85
88
for cmd_name in command_name_list():
86
cmd_object = breezy.commands.get_cmd_object(cmd_name)
89
cmd_object = brzlib.commands.get_cmd_object(cmd_name)
87
90
if cmd_object.hidden:
89
92
cmd_help = cmd_object.help()
93
96
tmp = '.TP\n.B "%s"\n%s\n' % (usage, firstline)
94
97
output = output + tmp
96
raise RuntimeError("Command '%s' has no help text" % (cmd_name))
99
raise RuntimeError, "Command '%s' has no help text" % (cmd_name)
100
103
def getcommand_help(params):
101
"""Shows individual options for a brz command"""
102
output = '.SH "COMMAND REFERENCE"\n'
104
"""Shows individual options for a bzr command"""
105
output='.SH "COMMAND REFERENCE"\n'
104
107
for cmd_name in command_name_list():
105
cmd_object = breezy.commands.get_cmd_object(cmd_name)
108
cmd_object = brzlib.commands.get_cmd_object(cmd_name)
106
109
if cmd_object.hidden:
108
111
formatted[cmd_name] = format_command(params, cmd_object)
117
120
"""Provides long help for each public command"""
118
121
subsection_header = '.SS "%s"\n' % (cmd._usage())
119
122
doc = "%s\n" % (cmd.__doc__)
120
doc = breezy.help_topics.help_as_plain_text(cmd.help())
123
doc = brzlib.help_topics.help_as_plain_text(cmd.help())
122
125
# A dot at the beginning of a line is interpreted as a macro.
123
126
# Simply join lines that begin with a dot with the previous
139
142
l += ', -' + short_name
140
143
l += (30 - len(l)) * ' ' + (help or '')
141
144
wrapped = textwrap.fill(l, initial_indent='',
142
subsequent_indent=30 * ' ',
143
break_long_words=False,
145
subsequent_indent=30*' ',
146
break_long_words=False,
145
148
option_str += wrapped + '\n'
166
169
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)
170
help = '.SS "bzr %s"\n' % alias
171
help += 'Alias for "%s", see "bzr %s".\n' % (cmd_name, cmd_name)
172
175
def environment_variables():
173
176
yield ".SH \"ENVIRONMENT\"\n"
175
from breezy.help_topics import known_env_variables
178
from brzlib.help_topics import known_env_variables
176
179
for k, desc in known_env_variables:
178
181
yield ".I \"%s\"\n" % k
182
185
man_preamble = """\
183
.\\\"Man page for Breezy (%(brzcmd)s)
186
.\\\"Man page for Bazaar (%(bzrcmd)s)
185
188
.\\\" Large parts of this file are autogenerated from the output of
186
.\\\" \"%(brzcmd)s help commands\"
187
.\\\" \"%(brzcmd)s help <cmd>\"
189
.\\\" \"%(bzrcmd)s help commands\"
190
.\\\" \"%(bzrcmd)s help <cmd>\"
190
193
.ie \\n(.g .ds Aq \\(aq
196
.TH brz 1 "%(datestamp)s" "%(version)s" "Breezy"
199
.TH bzr 1 "%(datestamp)s" "%(version)s" "Bazaar"
198
%(brzcmd)s - Breezy next-generation distributed version control
201
%(bzrcmd)s - Bazaar next-generation distributed version control
203
206
.I "command_options"
212
215
.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.
217
Bazaar (or %(bzrcmd)s) is a distributed version control system that is powerful,
218
friendly, and scalable. Bazaar is a project of Canonical Ltd and part of
219
the GNU Project to develop a free operating system.
217
Breezy keeps track of changes to software source code (or similar information);
221
Bazaar keeps track of changes to software source code (or similar information);
218
222
lets you explore who changed it, when, and why; merges concurrent changes; and
219
223
helps people work together in a team.
245
249
log10 = log --short -r -10..-1
247
.UR https://www.breezy-vcs.org/
248
.BR https://www.breezy-vcs.org/
251
.UR http://bazaar.canonical.com/
252
.BR http://bazaar.canonical.com/