Mercurial > hg
comparison doc/gendoc.py @ 42252:a42cc325b682
gendoc: nest command headers under category headers
Differential Revision: https://phab.mercurial-scm.org/D6329
author | Sietse Brouwer <sbbrouwer@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 12:41:48 +0200 |
parents | 037a97d62625 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42251:f9cdd732cb58 | 42252:a42cc325b682 |
---|---|
118 ui.write(_(b"\n[+] marked option can be specified multiple times\n")) | 118 ui.write(_(b"\n[+] marked option can be specified multiple times\n")) |
119 ui.write(b"\n") | 119 ui.write(b"\n") |
120 | 120 |
121 # print cmds | 121 # print cmds |
122 ui.write(minirst.section(_(b"Commands"))) | 122 ui.write(minirst.section(_(b"Commands"))) |
123 commandprinter(ui, table, minirst.subsection) | 123 commandprinter(ui, table, minirst.subsection, minirst.subsubsection) |
124 | 124 |
125 # print help topics | 125 # print help topics |
126 # The config help topic is included in the hgrc.5 man page. | 126 # The config help topic is included in the hgrc.5 man page. |
127 helpprinter(ui, helptable, minirst.section, exclude=[b'config']) | 127 helpprinter(ui, helptable, minirst.section, exclude=[b'config']) |
128 | 128 |
141 ui.write(minirst.subsection(extensionname)) | 141 ui.write(minirst.subsection(extensionname)) |
142 ui.write(b"%s\n\n" % gettext(pycompat.getdoc(mod))) | 142 ui.write(b"%s\n\n" % gettext(pycompat.getdoc(mod))) |
143 cmdtable = getattr(mod, 'cmdtable', None) | 143 cmdtable = getattr(mod, 'cmdtable', None) |
144 if cmdtable: | 144 if cmdtable: |
145 ui.write(minirst.subsubsection(_(b'Commands'))) | 145 ui.write(minirst.subsubsection(_(b'Commands'))) |
146 commandprinter(ui, cmdtable, minirst.subsubsubsection) | 146 commandprinter(ui, cmdtable, minirst.subsubsubsection, |
147 minirst.subsubsubsubsection) | |
147 | 148 |
148 def showtopic(ui, topic): | 149 def showtopic(ui, topic): |
149 extrahelptable = [ | 150 extrahelptable = [ |
150 ([b"common"], b'', loaddoc(b'common'), help.TOPIC_CATEGORY_MISC), | 151 ([b"common"], b'', loaddoc(b'common'), help.TOPIC_CATEGORY_MISC), |
151 ([b"hg.1"], b'', loaddoc(b'hg.1'), help.TOPIC_CATEGORY_CONFIG), | 152 ([b"hg.1"], b'', loaddoc(b'hg.1'), help.TOPIC_CATEGORY_CONFIG), |
175 if callable(doc): | 176 if callable(doc): |
176 doc = doc(ui) | 177 doc = doc(ui) |
177 ui.write(doc) | 178 ui.write(doc) |
178 ui.write(b"\n") | 179 ui.write(b"\n") |
179 | 180 |
180 def commandprinter(ui, cmdtable, sectionfunc): | 181 def commandprinter(ui, cmdtable, sectionfunc, subsectionfunc): |
182 """Render restructuredtext describing a list of commands and their | |
183 documentations, grouped by command category. | |
184 | |
185 Args: | |
186 ui: UI object to write the output to | |
187 cmdtable: a dict that maps a string of the command name plus its aliases | |
188 (separated with pipes) to a 3-tuple of (the command's function, a list | |
189 of its option descriptions, and a string summarizing available | |
190 options). Example, with aliases added for demonstration purposes: | |
191 | |
192 'phase|alias1|alias2': ( | |
193 <function phase at 0x7f0816b05e60>, | |
194 [ ('p', 'public', False, 'set changeset phase to public'), | |
195 ..., | |
196 ('r', 'rev', [], 'target revision', 'REV')], | |
197 '[-p|-d|-s] [-f] [-r] [REV...]' | |
198 ) | |
199 sectionfunc: minirst function to format command category headers | |
200 subsectionfunc: minirst function to format command headers | |
201 """ | |
181 h = {} | 202 h = {} |
182 for c, attr in cmdtable.items(): | 203 for c, attr in cmdtable.items(): |
183 f = c.split(b"|")[0] | 204 f = c.split(b"|")[0] |
184 f = f.lstrip(b"^") | 205 f = f.lstrip(b"^") |
185 h[f] = c | 206 h[f] = c |
219 # Print each command in the category | 240 # Print each command in the category |
220 for f in sorted(categorycmds): | 241 for f in sorted(categorycmds): |
221 if f.startswith(b"debug"): | 242 if f.startswith(b"debug"): |
222 continue | 243 continue |
223 d = get_cmd(h[f], cmdtable) | 244 d = get_cmd(h[f], cmdtable) |
224 ui.write(sectionfunc(d[b'cmd'])) | 245 ui.write(subsectionfunc(d[b'cmd'])) |
225 # short description | 246 # short description |
226 ui.write(d[b'desc'][0]) | 247 ui.write(d[b'desc'][0]) |
227 # synopsis | 248 # synopsis |
228 ui.write(b"::\n\n") | 249 ui.write(b"::\n\n") |
229 synopsislines = d[b'synopsis'].splitlines() | 250 synopsislines = d[b'synopsis'].splitlines() |