comparison doc/gendoc.py @ 42249:3816e361e3d8

gendoc: group commands by category in man page and HTML help Make Mercurial's man page and HTML help group commands by category, and present the categories in a helpful order. `hg help` already does this; this patch uses the same metadata. This patch uses the same header level for command categories and for commands. A subsequent patch will push the command headers down one level. Differential Revision: https://phab.mercurial-scm.org/D6326
author Sietse Brouwer <sbbrouwer@gmail.com>
date Fri, 26 Apr 2019 17:53:01 +0200
parents 0786b791b3b5
children 037a97d62625
comparison
equal deleted inserted replaced
42248:0786b791b3b5 42249:3816e361e3d8
183 f = c.split(b"|")[0] 183 f = c.split(b"|")[0]
184 f = f.lstrip(b"^") 184 f = f.lstrip(b"^")
185 h[f] = c 185 h[f] = c
186 cmds = h.keys() 186 cmds = h.keys()
187 187
188 if True: 188 def helpcategory(cmd):
189 for f in sorted(cmds): 189 """Given a canonical command name from `cmds` (above), retrieve its
190 help category. If helpcategory is None, default to CATEGORY_NONE.
191 """
192 fullname = h[cmd]
193 details = cmdtable[fullname]
194 helpcategory = details[0].helpcategory
195 return helpcategory or help.registrar.command.CATEGORY_NONE
196
197 # Print the help for each command. We present the commands grouped by
198 # category, and we use help.CATEGORY_ORDER as a guide for a helpful order
199 # in which to present the categories.
200 cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER}
201 for cmd in cmds:
202 cmdsbycategory[helpcategory(cmd)].append(cmd)
203
204 for category in help.CATEGORY_ORDER:
205 categorycmds = cmdsbycategory[category]
206 if not categorycmds:
207 # Skip empty categories
208 continue
209 # Print a section header for the category.
210 # For now, the category header is at the same level as the headers for
211 # the commands in the category; this is fixed in the next commit.
212 ui.write(sectionfunc(help.CATEGORY_NAMES[category]))
213 # Print each command in the category
214 for f in sorted(categorycmds):
190 if f.startswith(b"debug"): 215 if f.startswith(b"debug"):
191 continue 216 continue
192 d = get_cmd(h[f], cmdtable) 217 d = get_cmd(h[f], cmdtable)
193 ui.write(sectionfunc(d[b'cmd'])) 218 ui.write(sectionfunc(d[b'cmd']))
194 # short description 219 # short description