Patchwork D6326: gendoc: group commands by category in man page and HTML help

login
register
mail settings
Submitter phabricator
Date May 5, 2019, 5:12 a.m.
Message ID <7efde472651619ec9a6472abb464fd6f@localhost.localdomain>
Download mbox | patch
Permalink /patch/39954/
State Not Applicable
Headers show

Comments

phabricator - May 5, 2019, 5:12 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG3816e361e3d8: gendoc: group commands by category in man page and HTML help (authored by Sietse, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D6326?vs=14998&id=15012#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6326?vs=14998&id=15012

REVISION DETAIL
  https://phab.mercurial-scm.org/D6326

AFFECTED FILES
  doc/gendoc.py

CHANGE DETAILS




To: Sietse, #hg-reviewers, martinvonz
Cc: martinvonz, mercurial-devel

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -185,8 +185,33 @@ 
         h[f] = c
     cmds = h.keys()
 
-    if True:
-        for f in sorted(cmds):
+    def helpcategory(cmd):
+        """Given a canonical command name from `cmds` (above), retrieve its
+        help category. If helpcategory is None, default to CATEGORY_NONE.
+        """
+        fullname = h[cmd]
+        details = cmdtable[fullname]
+        helpcategory = details[0].helpcategory
+        return helpcategory or help.registrar.command.CATEGORY_NONE
+
+    # 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:
+            # Skip empty categories
+            continue
+        # Print a section header for the category.
+        # For now, the category header is at the same level as the headers for
+        # the commands in the category; this is fixed in the next commit.
+        ui.write(sectionfunc(help.CATEGORY_NAMES[category]))
+        # Print each command in the category
+        for f in sorted(categorycmds):
             if f.startswith(b"debug"):
                 continue
             d = get_cmd(h[f], cmdtable)