changeset 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 f9cdd732cb58
files doc/gendoc.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/doc/gendoc.py	Fri Apr 26 17:53:01 2019 +0200
+++ b/doc/gendoc.py	Fri May 03 15:37:08 2019 +0200
@@ -194,13 +194,19 @@
         helpcategory = details[0].helpcategory
         return helpcategory or help.registrar.command.CATEGORY_NONE
 
+    cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER}
+    for cmd in cmds:
+        # If a command category wasn't registered, the command won't get
+        # rendered below, so we raise an AssertionError.
+        if helpcategory(cmd) not in cmdsbycategory:
+            raise AssertionError(
+                "The following command did not register its (category) in "
+                "help.CATEGORY_ORDER: %s (%s)" % (cmd, helpcategory(cmd)))
+        cmdsbycategory[helpcategory(cmd)].append(cmd)
+
     # Print the help for each command. We present the commands grouped by
     # category, and we use help.CATEGORY_ORDER as a guide for a helpful order
     # in which to present the categories.
-    cmdsbycategory = {category: [] for category in help.CATEGORY_ORDER}
-    for cmd in cmds:
-        cmdsbycategory[helpcategory(cmd)].append(cmd)
-
     for category in help.CATEGORY_ORDER:
         categorycmds = cmdsbycategory[category]
         if not categorycmds:
@@ -250,7 +256,6 @@
             if d[b'aliases']:
                 ui.write(_(b"    aliases: %s\n\n") % b" ".join(d[b'aliases']))
 
-
 def allextensionnames():
     return set(extensions.enabled().keys()) | set(extensions.disabled().keys())