##// END OF EJS Templates
doc: refactor gendoc for better reusability...
Ludovic Chabant -
r52913:1f5974f8 default
parent child Browse files
Show More
@@ -1,346 +1,433 b''
1 #!/usr/bin/env python3
1 #!/usr/bin/env python3
2 """usage: %s DOC ...
2 """usage: %s DOC ...
3
3
4 where DOC is the name of a document
4 where DOC is the name of a document
5 """
5 """
6
6
7
7
8 import os
8 import os
9 import sys
9 import sys
10 import textwrap
10 import textwrap
11 import argparse
11
12
12 try:
13 try:
13 import msvcrt
14 import msvcrt
14
15
15 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
16 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
16 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
17 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
17 except ImportError:
18 except ImportError:
18 pass
19 pass
19
20
20 # This script is executed during installs and may not have C extensions
21 # This script is executed during installs and may not have C extensions
21 # available. Relax C module requirements.
22 # available. Relax C module requirements.
22 os.environ['HGMODULEPOLICY'] = 'allow'
23 os.environ['HGMODULEPOLICY'] = 'allow'
23 # import from the live mercurial repo
24 # import from the live mercurial repo
24 sys.path.insert(0, os.path.abspath(".."))
25 sys.path.insert(0, os.path.abspath(".."))
25 from mercurial import demandimport
26 from mercurial import demandimport
26
27
27 demandimport.enable()
28 demandimport.enable()
28
29
29 from mercurial import (
30 from mercurial import (
30 commands,
31 commands,
31 encoding,
32 encoding,
32 extensions,
33 extensions,
33 fancyopts,
34 fancyopts,
34 help,
35 help,
35 minirst,
36 minirst,
36 pycompat,
37 pycompat,
37 ui as uimod,
38 ui as uimod,
38 )
39 )
39 from mercurial.i18n import (
40 from mercurial.i18n import (
40 gettext,
41 gettext,
41 _,
42 _,
42 )
43 )
43 from mercurial.utils import stringutil
44 from mercurial.utils import stringutil
44
45
45 table = commands.table
46 table = commands.table
46 globalopts = commands.globalopts
47 globalopts = commands.globalopts
47 helptable = help.helptable
48 helptable = help.helptable
48 loaddoc = help.loaddoc
49 loaddoc = help.loaddoc
49
50
50
51
51 def get_desc(docstr):
52 def get_desc(docstr):
52 if not docstr:
53 if not docstr:
53 return b"", b""
54 return b"", b""
54 # sanitize
55 # sanitize
55 docstr = docstr.strip(b"\n")
56 docstr = docstr.strip(b"\n")
56 docstr = docstr.rstrip()
57 docstr = docstr.rstrip()
57 shortdesc = docstr.splitlines()[0].strip()
58 shortdesc = docstr.splitlines()[0].strip()
58
59
59 i = docstr.find(b"\n")
60 i = docstr.find(b"\n")
60 if i != -1:
61 if i != -1:
61 desc = docstr[i + 2 :]
62 desc = docstr[i + 2 :]
62 else:
63 else:
63 desc = shortdesc
64 desc = shortdesc
64
65
65 desc = textwrap.dedent(desc.decode('latin1')).encode('latin1')
66 desc = textwrap.dedent(desc.decode('latin1')).encode('latin1')
66
67
67 return (shortdesc, desc)
68 return (shortdesc, desc)
68
69
69
70
70 def get_opts(opts):
71 def get_opts(opts):
71 for opt in opts:
72 for opt in opts:
72 if len(opt) == 5:
73 if len(opt) == 5:
73 shortopt, longopt, default, desc, optlabel = opt
74 shortopt, longopt, default, desc, optlabel = opt
74 else:
75 else:
75 shortopt, longopt, default, desc = opt
76 shortopt, longopt, default, desc = opt
76 optlabel = _(b"VALUE")
77 optlabel = _(b"VALUE")
77 allopts = []
78 allopts = []
78 if shortopt:
79 if shortopt:
79 allopts.append(b"-%s" % shortopt)
80 allopts.append(b"-%s" % shortopt)
80 if longopt:
81 if longopt:
81 allopts.append(b"--%s" % longopt)
82 allopts.append(b"--%s" % longopt)
82 if isinstance(default, list):
83 if isinstance(default, list):
83 allopts[-1] += b" <%s[+]>" % optlabel
84 allopts[-1] += b" <%s[+]>" % optlabel
84 elif (default is not None) and not isinstance(default, bool):
85 elif (default is not None) and not isinstance(default, bool):
85 allopts[-1] += b" <%s>" % optlabel
86 allopts[-1] += b" <%s>" % optlabel
86 if b'\n' in desc:
87 if b'\n' in desc:
87 # only remove line breaks and indentation
88 # only remove line breaks and indentation
88 desc = b' '.join(l.lstrip() for l in desc.split(b'\n'))
89 desc = b' '.join(l.lstrip() for l in desc.split(b'\n'))
89 if isinstance(default, fancyopts.customopt):
90 if isinstance(default, fancyopts.customopt):
90 default = default.getdefaultvalue()
91 default = default.getdefaultvalue()
91 if default:
92 if default:
92 default = stringutil.forcebytestr(default)
93 default = stringutil.forcebytestr(default)
93 desc += _(b" (default: %s)") % default
94 desc += _(b" (default: %s)") % default
94 yield (b", ".join(allopts), desc)
95 yield (b", ".join(allopts), desc)
95
96
96
97
97 def get_cmd(cmd, cmdtable):
98 def get_cmd(cmd, cmdtable):
98 d = {}
99 d = {}
99 attr = cmdtable[cmd]
100 attr = cmdtable[cmd]
100 cmds = cmd.lstrip(b"^").split(b"|")
101 cmds = cmd.lstrip(b"^").split(b"|")
101
102
102 d[b'cmd'] = cmds[0]
103 d[b'cmd'] = cmds[0]
103 d[b'aliases'] = cmd.split(b"|")[1:]
104 d[b'aliases'] = cmd.split(b"|")[1:]
104 d[b'desc'] = get_desc(gettext(pycompat.getdoc(attr[0])))
105 d[b'desc'] = get_desc(gettext(pycompat.getdoc(attr[0])))
105 d[b'opts'] = list(get_opts(attr[1]))
106 d[b'opts'] = list(get_opts(attr[1]))
106
107
107 s = b'hg ' + cmds[0]
108 s = b'hg ' + cmds[0]
108 if len(attr) > 2:
109 if len(attr) > 2:
109 if not attr[2].startswith(b'hg'):
110 if not attr[2].startswith(b'hg'):
110 s += b' ' + attr[2]
111 s += b' ' + attr[2]
111 else:
112 else:
112 s = attr[2]
113 s = attr[2]
113 d[b'synopsis'] = s.strip()
114 d[b'synopsis'] = s.strip()
114
115
115 return d
116 return d
116
117
117
118
118 def showdoc(ui):
119 def showdoc(ui, debugcmds=False):
119 # print options
120 # print options
120 ui.write(minirst.section(_(b"Options")))
121 ui.write(minirst.section(_(b"Options")))
121 multioccur = False
122 multioccur = False
122 for optstr, desc in get_opts(globalopts):
123 for optstr, desc in get_opts(globalopts):
123 ui.write(b"%s\n %s\n\n" % (optstr, desc))
124 ui.write(b"%s\n %s\n\n" % (optstr, desc))
124 if optstr.endswith(b"[+]>"):
125 if optstr.endswith(b"[+]>"):
125 multioccur = True
126 multioccur = True
126 if multioccur:
127 if multioccur:
127 ui.write(_(b"\n[+] marked option can be specified multiple times\n"))
128 ui.write(_(b"\n[+] marked option can be specified multiple times\n"))
128 ui.write(b"\n")
129 ui.write(b"\n")
129
130
130 # print cmds
131 # print cmds
131 ui.write(minirst.section(_(b"Commands")))
132 ui.write(minirst.section(_(b"Commands")))
132 commandprinter(ui, table, minirst.subsection, minirst.subsubsection)
133 commandprinter(
134 ui,
135 table,
136 minirst.subsection,
137 minirst.subsubsection,
138 debugcmds=debugcmds,
139 )
133
140
134 # print help topics
141 # print help topics
135 # The config help topic is included in the hgrc.5 man page.
142 # The config help topic is included in the hgrc.5 man page.
136 helpprinter(ui, helptable, minirst.section, exclude=[b'config'])
143 topics = findtopics(helptable, exclude=[b'config'])
144 helpprinter(ui, topics, minirst.section)
137
145
138 ui.write(minirst.section(_(b"Extensions")))
146 ui.write(minirst.section(_(b"Extensions")))
139 ui.write(
147 ui.write(
140 _(
148 _(
141 b"This section contains help for extensions that are "
149 b"This section contains help for extensions that are "
142 b"distributed together with Mercurial. Help for other "
150 b"distributed together with Mercurial. Help for other "
143 b"extensions is available in the help system."
151 b"extensions is available in the help system."
144 )
152 )
145 )
153 )
146 ui.write(
154 ui.write(
147 (
155 (
148 b"\n\n"
156 b"\n\n"
149 b".. contents::\n"
157 b".. contents::\n"
150 b" :class: htmlonly\n"
158 b" :class: htmlonly\n"
151 b" :local:\n"
159 b" :local:\n"
152 b" :depth: 1\n\n"
160 b" :depth: 1\n\n"
153 )
161 )
154 )
162 )
155
163
156 for extensionname in sorted(allextensionnames()):
164 for extensionname in sorted(allextensionnames()):
157 mod = extensions.load(ui, extensionname, None)
165 mod = extensions.load(ui, extensionname, None)
158 ui.write(minirst.subsection(extensionname))
166 ui.write(minirst.subsection(extensionname))
159 ext_doc = help.ext_help(ui, mod)
167 ext_doc = help.ext_help(ui, mod)
160 ui.write(b"%s\n\n" % ext_doc)
168 ui.write(b"%s\n\n" % ext_doc)
161 cmdtable = getattr(mod, 'cmdtable', None)
169 cmdtable = getattr(mod, 'cmdtable', None)
162 if cmdtable:
170 if cmdtable:
163 ui.write(minirst.subsubsection(_(b'Commands')))
171 ui.write(minirst.subsubsection(_(b'Commands')))
164 commandprinter(
172 commandprinter(
165 ui,
173 ui,
166 cmdtable,
174 cmdtable,
167 minirst.subsubsubsection,
175 minirst.subsubsubsection,
168 minirst.subsubsubsubsection,
176 minirst.subsubsubsubsection,
177 debugcmds=debugcmds,
169 )
178 )
170
179
171
180
172 def showtopic(ui, topic):
181 def gettopicstable():
173 extrahelptable = [
182 extrahelptable = [
174 ([b"common"], b'', loaddoc(b'common'), help.TOPIC_CATEGORY_MISC),
183 ([b"common"], b'', loaddoc(b'common'), help.TOPIC_CATEGORY_MISC),
175 ([b"hg.1"], b'', loaddoc(b'hg.1'), help.TOPIC_CATEGORY_CONFIG),
184 ([b"hg.1"], b'', loaddoc(b'hg.1'), help.TOPIC_CATEGORY_CONFIG),
176 ([b"hg-ssh.8"], b'', loaddoc(b'hg-ssh.8'), help.TOPIC_CATEGORY_CONFIG),
185 ([b"hg-ssh.8"], b'', loaddoc(b'hg-ssh.8'), help.TOPIC_CATEGORY_CONFIG),
177 (
186 (
178 [b"hgignore.5"],
187 [b"hgignore.5"],
179 b'',
188 b'',
180 loaddoc(b'hgignore.5'),
189 loaddoc(b'hgignore.5'),
181 help.TOPIC_CATEGORY_CONFIG,
190 help.TOPIC_CATEGORY_CONFIG,
182 ),
191 ),
183 ([b"hgrc.5"], b'', loaddoc(b'hgrc.5'), help.TOPIC_CATEGORY_CONFIG),
192 ([b"hgrc.5"], b'', loaddoc(b'hgrc.5'), help.TOPIC_CATEGORY_CONFIG),
193 ([b"hg-ssh.8.gendoc"], b'', b'', help.TOPIC_CATEGORY_CONFIG),
184 (
194 (
185 [b"hgignore.5.gendoc"],
195 [b"hgignore.5.gendoc"],
186 b'',
196 b'',
187 loaddoc(b'hgignore'),
197 loaddoc(b'hgignore'),
188 help.TOPIC_CATEGORY_CONFIG,
198 help.TOPIC_CATEGORY_CONFIG,
189 ),
199 ),
190 (
200 (
191 [b"hgrc.5.gendoc"],
201 [b"hgrc.5.gendoc"],
192 b'',
202 b'',
193 loaddoc(b'config'),
203 loaddoc(b'config'),
194 help.TOPIC_CATEGORY_CONFIG,
204 help.TOPIC_CATEGORY_CONFIG,
195 ),
205 ),
196 ]
206 ]
197 helpprinter(ui, helptable + extrahelptable, None, include=[topic])
207 return helptable + extrahelptable
198
208
199
209
200 def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]):
210 def findtopics(helptable, include=[], exclude=[]):
211 """Find topics whose names match the given include/exclude rules
212
213 Note that exclude rules take precedence over include rules.
214 """
215 found = []
201 for h in helptable:
216 for h in helptable:
202 names, sec, doc = h[0:3]
217 names, sec, doc = h[0:3]
203 if exclude and names[0] in exclude:
218 if exclude and names[0] in exclude:
204 continue
219 continue
205 if include and names[0] not in include:
220 if include and names[0] not in include:
206 continue
221 continue
222 found.append((names, sec, doc))
223 return found
224
225
226 def showtopic(ui, topic, wraptpl=False):
227 """Render a help topic
228
229 Args:
230 ui: the UI object to output to
231 topic: the topic name to output
232 wraptpl: whether to wrap the output in the individual help topic
233 pages' header/footer
234 """
235 found = findtopics(gettopicstable(), include=[topic])
236 if not found:
237 ui.write_err(_(b"ERROR: no such topic: %s\n") % topic)
238 sys.exit(1)
239
240 if wraptpl:
241 header = _rendertpl(
242 'topicheader.txt',
243 {'topicname': topic, 'topictitle': minirst.section(found[0][1])},
244 )
245 ui.write(header.encode())
246 helpprinter(ui, found, None)
247 return True
248
249
250 def helpprinter(ui, topics, sectionfunc):
251 """Print a help topic
252
253 Args:
254 ui: the UI object to output to
255 topics: a list of help topics to output
256 sectionfunc: a callback to write the section title
257 """
258 for h in topics:
259 names, sec, doc = h[0:3]
207 for name in names:
260 for name in names:
208 ui.write(b".. _%s:\n" % name)
261 ui.write(b".. _%s:\n" % name)
209 ui.write(b"\n")
262 ui.write(b"\n")
210 if sectionfunc:
263 if sectionfunc:
211 ui.write(sectionfunc(sec))
264 ui.write(sectionfunc(sec))
212 if callable(doc):
265 if callable(doc):
213 doc = doc(ui)
266 doc = doc(ui)
214 ui.write(doc)
267 ui.write(doc)
215 ui.write(b"\n")
268 ui.write(b"\n")
216
269
217
270
218 def commandprinter(ui, cmdtable, sectionfunc, subsectionfunc):
271 def commandprinter(ui, cmdtable, sectionfunc, subsectionfunc, debugcmds=False):
219 """Render restructuredtext describing a list of commands and their
272 """Render restructuredtext describing a list of commands and their
220 documentations, grouped by command category.
273 documentations, grouped by command category.
221
274
222 Args:
275 Args:
223 ui: UI object to write the output to
276 ui: UI object to write the output to
224 cmdtable: a dict that maps a string of the command name plus its aliases
277 cmdtable: a dict that maps a string of the command name plus its aliases
225 (separated with pipes) to a 3-tuple of (the command's function, a list
278 (separated with pipes) to a 3-tuple of (the command's function, a list
226 of its option descriptions, and a string summarizing available
279 of its option descriptions, and a string summarizing available
227 options). Example, with aliases added for demonstration purposes:
280 options). Example, with aliases added for demonstration purposes:
228
281
229 'phase|alias1|alias2': (
282 'phase|alias1|alias2': (
230 <function phase at 0x7f0816b05e60>,
283 <function phase at 0x7f0816b05e60>,
231 [ ('p', 'public', False, 'set changeset phase to public'),
284 [ ('p', 'public', False, 'set changeset phase to public'),
232 ...,
285 ...,
233 ('r', 'rev', [], 'target revision', 'REV')],
286 ('r', 'rev', [], 'target revision', 'REV')],
234 '[-p|-d|-s] [-f] [-r] [REV...]'
287 '[-p|-d|-s] [-f] [-r] [REV...]'
235 )
288 )
236 sectionfunc: minirst function to format command category headers
289 sectionfunc: minirst function to format command category headers
237 subsectionfunc: minirst function to format command headers
290 subsectionfunc: minirst function to format command headers
238 """
291 """
239 h = {}
292 h = allcommandnames(cmdtable, debugcmds=debugcmds)
240 for c, attr in cmdtable.items():
241 f = c.split(b"|")[0]
242 f = f.lstrip(b"^")
243 h[f] = c
244 cmds = h.keys()
293 cmds = h.keys()
245
294
246 def helpcategory(cmd):
295 def helpcategory(cmd):
247 """Given a canonical command name from `cmds` (above), retrieve its
296 """Given a canonical command name from `cmds` (above), retrieve its
248 help category. If helpcategory is None, default to CATEGORY_NONE.
297 help category. If helpcategory is None, default to CATEGORY_NONE.
249 """
298 """
250 fullname = h[cmd]
299 fullname = h[cmd]
251 details = cmdtable[fullname]
300 details = cmdtable[fullname]
252 helpcategory = details[0].helpcategory
301 helpcategory = details[0].helpcategory
253 return helpcategory or help.registrar.command.CATEGORY_NONE
302 return helpcategory or help.registrar.command.CATEGORY_NONE
254
303
255 cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER}
304 cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER}
256 for cmd in cmds:
305 for cmd in cmds:
257 # If a command category wasn't registered, the command won't get
306 # If a command category wasn't registered, the command won't get
258 # rendered below, so we raise an AssertionError.
307 # rendered below, so we raise an AssertionError.
259 if helpcategory(cmd) not in cmdsbycategory:
308 if helpcategory(cmd) not in cmdsbycategory:
260 raise AssertionError(
309 raise AssertionError(
261 "The following command did not register its (category) in "
310 "The following command did not register its (category) in "
262 "help.CATEGORY_ORDER: %s (%s)" % (cmd, helpcategory(cmd))
311 "help.CATEGORY_ORDER: %s (%s)" % (cmd, helpcategory(cmd))
263 )
312 )
264 cmdsbycategory[helpcategory(cmd)].append(cmd)
313 cmdsbycategory[helpcategory(cmd)].append(cmd)
265
314
266 # Print the help for each command. We present the commands grouped by
315 # Print the help for each command. We present the commands grouped by
267 # category, and we use help.CATEGORY_ORDER as a guide for a helpful order
316 # category, and we use help.CATEGORY_ORDER as a guide for a helpful order
268 # in which to present the categories.
317 # in which to present the categories.
269 for category in help.CATEGORY_ORDER:
318 for category in help.CATEGORY_ORDER:
270 categorycmds = cmdsbycategory[category]
319 categorycmds = cmdsbycategory[category]
271 if not categorycmds:
320 if not categorycmds:
272 # Skip empty categories
321 # Skip empty categories
273 continue
322 continue
274 # Print a section header for the category.
323 # Print a section header for the category.
275 # For now, the category header is at the same level as the headers for
324 # For now, the category header is at the same level as the headers for
276 # the commands in the category; this is fixed in the next commit.
325 # the commands in the category; this is fixed in the next commit.
277 ui.write(sectionfunc(help.CATEGORY_NAMES[category]))
326 ui.write(sectionfunc(help.CATEGORY_NAMES[category]))
278 # Print each command in the category
327 # Print each command in the category
279 for f in sorted(categorycmds):
328 for f in sorted(categorycmds):
280 if f.startswith(b"debug"):
281 continue
282 d = get_cmd(h[f], cmdtable)
329 d = get_cmd(h[f], cmdtable)
283 ui.write(subsectionfunc(d[b'cmd']))
330 ui.write(subsectionfunc(d[b'cmd']))
284 # short description
331 # short description
285 ui.write(d[b'desc'][0])
332 ui.write(d[b'desc'][0])
286 # synopsis
333 # synopsis
287 ui.write(b"::\n\n")
334 ui.write(b"::\n\n")
288 synopsislines = d[b'synopsis'].splitlines()
335 synopsislines = d[b'synopsis'].splitlines()
289 for line in synopsislines:
336 for line in synopsislines:
290 # some commands (such as rebase) have a multi-line
337 # some commands (such as rebase) have a multi-line
291 # synopsis
338 # synopsis
292 ui.write(b" %s\n" % line)
339 ui.write(b" %s\n" % line)
293 ui.write(b'\n')
340 ui.write(b'\n')
294 # description
341 # description
295 ui.write(b"%s\n\n" % d[b'desc'][1])
342 ui.write(b"%s\n\n" % d[b'desc'][1])
343
296 # options
344 # options
297 opt_output = list(d[b'opts'])
345 def _optsection(s):
298 if opt_output:
346 return b"%s:\n\n" % s
299 opts_len = max([len(line[0]) for line in opt_output])
347
300 ui.write(_(b"Options:\n\n"))
348 _optionsprinter(ui, d, _optsection)
301 multioccur = False
302 for optstr, desc in opt_output:
303 if desc:
304 s = b"%-*s %s" % (opts_len, optstr, desc)
305 else:
306 s = optstr
307 ui.write(b"%s\n" % s)
308 if optstr.endswith(b"[+]>"):
309 multioccur = True
310 if multioccur:
311 ui.write(
312 _(
313 b"\n[+] marked option can be specified"
314 b" multiple times\n"
315 )
316 )
317 ui.write(b"\n")
318 # aliases
349 # aliases
319 if d[b'aliases']:
350 if d[b'aliases']:
320 # Note the empty comment, this is required to separate this
351 # Note the empty comment, this is required to separate this
321 # (which should be a blockquote) from any preceding things (such
352 # (which should be a blockquote) from any preceding things (such
322 # as a definition list).
353 # as a definition list).
323 ui.write(
354 ui.write(
324 _(b"..\n\n aliases: %s\n\n") % b" ".join(d[b'aliases'])
355 _(b"..\n\n aliases: %s\n\n") % b" ".join(d[b'aliases'])
325 )
356 )
326
357
327
358
359 def _optionsprinter(ui, cmd, sectionfunc):
360 """Outputs the list of options for a given command object"""
361 opt_output = list(cmd[b'opts'])
362 if opt_output:
363 opts_len = max([len(line[0]) for line in opt_output])
364 ui.write(sectionfunc(_(b"Options")))
365 multioccur = False
366 for optstr, desc in opt_output:
367 if desc:
368 s = b"%-*s %s" % (opts_len, optstr, desc)
369 else:
370 s = optstr
371 ui.write(b"%s\n" % s)
372 if optstr.endswith(b"[+]>"):
373 multioccur = True
374 if multioccur:
375 ui.write(
376 _(b"\n[+] marked option can be specified multiple times\n")
377 )
378 ui.write(b"\n")
379
380
381 def allcommandnames(cmdtable, debugcmds=False):
382 """Get a collection of all command names in the given command table
383
384 Args:
385 cmdtable: the command table to get the names from
386 debugcmds: whether to include debug commands
387
388 Returns a dictionary where the keys are the main command names, and the
389 values are the "raw" names (in the form of `name|alias1|alias2`).
390 """
391 allcmdnames = {}
392 for rawnames, attr in cmdtable.items():
393 mainname = rawnames.split(b"|")[0].lstrip(b"^")
394 if not debugcmds and mainname.startswith(b"debug"):
395 continue
396 allcmdnames[mainname] = rawnames
397 return allcmdnames
398
399
328 def allextensionnames():
400 def allextensionnames():
401 """Get a set of all known extension names"""
329 return set(extensions.enabled().keys()) | set(extensions.disabled().keys())
402 return set(extensions.enabled().keys()) | set(extensions.disabled().keys())
330
403
331
404
332 if __name__ == "__main__":
405 if __name__ == "__main__":
333 doc = b'hg.1.gendoc'
406 parser = argparse.ArgumentParser(
334 if len(sys.argv) > 1:
407 prog='gendoc', description="Generate mercurial documentation files"
335 doc = encoding.strtolocal(sys.argv[1])
408 )
409 parser.add_argument('doc', default='hg.1.gendoc', nargs='?')
410 parser.add_argument(
411 '-d',
412 '--debug-cmds',
413 action='store_true',
414 help="Show debug commands in help pages",
415 )
416 args = parser.parse_args()
417
418 doc = encoding.strtolocal(args.doc)
419 debugcmds = args.debug_cmds
336
420
337 ui = uimod.ui.load()
421 ui = uimod.ui.load()
338 # Trigger extensions to load. This is disabled by default because it uses
422 # Trigger extensions to load. This is disabled by default because it uses
339 # the current user's configuration, which is often not what is wanted.
423 # the current user's configuration, which is often not what is wanted.
340 if encoding.environ.get(b'GENDOC_LOAD_CONFIGURED_EXTENSIONS', b'0') != b'0':
424 if encoding.environ.get(b'GENDOC_LOAD_CONFIGURED_EXTENSIONS', b'0') != b'0':
341 extensions.loadall(ui)
425 extensions.loadall(ui)
342
426
427 # ui.debugflag determines if the help module returns debug commands to us.
428 ui.debugflag = debugcmds
429
343 if doc == b'hg.1.gendoc':
430 if doc == b'hg.1.gendoc':
344 showdoc(ui)
431 showdoc(ui)
345 else:
432 else:
346 showtopic(ui, encoding.strtolocal(sys.argv[1]))
433 showtopic(ui, doc)
General Comments 0
You need to be logged in to leave comments. Login now