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