Mercurial > hg
comparison doc/gendoc.py @ 42250:037a97d62625
gendoc: guarantee that all commands were processed
The new logic renders the commands belonging to each category in turn.
Commands with an unregistered category are at risk of getting skipped
because their category is not in the list. By comparing the list of all
commands to a log of processed commands, we can detect commands with
unregistered categories and fail with an error message.
Differential Revision: https://phab.mercurial-scm.org/D6327
author | Sietse Brouwer <sbbrouwer@gmail.com> |
---|---|
date | Fri, 03 May 2019 15:37:08 +0200 |
parents | 3816e361e3d8 |
children | a42cc325b682 |
comparison
equal
deleted
inserted
replaced
42249:3816e361e3d8 | 42250:037a97d62625 |
---|---|
192 fullname = h[cmd] | 192 fullname = h[cmd] |
193 details = cmdtable[fullname] | 193 details = cmdtable[fullname] |
194 helpcategory = details[0].helpcategory | 194 helpcategory = details[0].helpcategory |
195 return helpcategory or help.registrar.command.CATEGORY_NONE | 195 return helpcategory or help.registrar.command.CATEGORY_NONE |
196 | 196 |
197 cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER} | |
198 for cmd in cmds: | |
199 # If a command category wasn't registered, the command won't get | |
200 # rendered below, so we raise an AssertionError. | |
201 if helpcategory(cmd) not in cmdsbycategory: | |
202 raise AssertionError( | |
203 "The following command did not register its (category) in " | |
204 "help.CATEGORY_ORDER: %s (%s)" % (cmd, helpcategory(cmd))) | |
205 cmdsbycategory[helpcategory(cmd)].append(cmd) | |
206 | |
197 # Print the help for each command. We present the commands grouped by | 207 # 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 | 208 # category, and we use help.CATEGORY_ORDER as a guide for a helpful order |
199 # in which to present the categories. | 209 # 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: | 210 for category in help.CATEGORY_ORDER: |
205 categorycmds = cmdsbycategory[category] | 211 categorycmds = cmdsbycategory[category] |
206 if not categorycmds: | 212 if not categorycmds: |
207 # Skip empty categories | 213 # Skip empty categories |
208 continue | 214 continue |
248 ui.write(b"\n") | 254 ui.write(b"\n") |
249 # aliases | 255 # aliases |
250 if d[b'aliases']: | 256 if d[b'aliases']: |
251 ui.write(_(b" aliases: %s\n\n") % b" ".join(d[b'aliases'])) | 257 ui.write(_(b" aliases: %s\n\n") % b" ".join(d[b'aliases'])) |
252 | 258 |
253 | |
254 def allextensionnames(): | 259 def allextensionnames(): |
255 return set(extensions.enabled().keys()) | set(extensions.disabled().keys()) | 260 return set(extensions.enabled().keys()) | set(extensions.disabled().keys()) |
256 | 261 |
257 if __name__ == "__main__": | 262 if __name__ == "__main__": |
258 doc = b'hg.1.gendoc' | 263 doc = b'hg.1.gendoc' |