# HG changeset patch # User Sietse Brouwer # Date 1556184734 -7200 # Thu Apr 25 11:32:14 2019 +0200 # Node ID 3e08f93f7e8b6bb85d21efbd11c9f72ac53eabb9 # Parent 5d9bfb5ddefbcd4e04f8bd795ec6a92614241241 SBB: order commands in man page by category diff --git a/doc/gendoc.py b/doc/gendoc.py --- a/doc/gendoc.py +++ b/doc/gendoc.py @@ -185,8 +185,31 @@ h[f] = c cmds = h.keys() - if True: - for f in sorted(cmds): + def helpcategory(cmd, h=h, cmdtable=cmdtable): + """Given a canonical command name from `cmds` (above), retrieve its + help category. + """ + fullname = h[cmd] + details = cmdtable[fullname] + helpcategory = details[0].helpcategory + return helpcategory + + # 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. + for category in help.CATEGORY_ORDER: + # Make a list of the commands in this category. + cmds_in_category = sorted([ + cmd for cmd in cmds + if helpcategory(cmd) == category]) + # Print a section header for the category. Skip empty categories. For + # now, the category header is at the same level as the headers for the + # commands in the category. This is because the commands are already at + # man page level .SS, and there is no lower level than that. + if cmds_in_category: + ui.write(sectionfunc(help.CATEGORY_NAMES[category])) + # Print each command in the category + for f in sorted(cmds_in_category): if f.startswith(b"debug"): continue d = get_cmd(h[f], cmdtable)