[PATCH 1 of 2] gendoc: automatically create help for default extensions

Erik Zielke ez at aragost.com
Wed Oct 20 10:54:05 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1287589509 -7200
# Node ID 905b4645bfb8f9fc12fe70224b86a3cd39625c87
# Parent  51031203fc17ff846e07c8cb2fe5a2b71c6a4af4
gendoc: automatically create help for default extensions.

Adds a section in the hg.1 manpage and corresponding hg.1.html
file. Each extension is listed with its module docstring, followed by
the commands defined by that extendsion.

Creates help for extensions by extracting doc strings from the extension modules
and its commands.

diff -r 51031203fc17 -r 905b4645bfb8 doc/gendoc.py
--- a/doc/gendoc.py	Tue Oct 19 13:50:03 2010 +0200
+++ b/doc/gendoc.py	Wed Oct 20 17:45:09 2010 +0200
@@ -8,6 +8,7 @@
 from mercurial.commands import table, globalopts
 from mercurial.i18n import _
 from mercurial.help import helptable
+from mercurial import extensions
 
 def get_desc(docstr):
     if not docstr:
@@ -66,6 +67,10 @@
         ui.write("%s\n%s\n\n" % (s, "-" * encoding.colwidth(s)))
     def subsection(s):
         ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s)))
+    def subsubsection(s):
+        ui.write("%s\n%s\n\n" % (s, "." * encoding.colwidth(s)))
+    def subsubsubsection(s):
+        ui.write("%s\n%s\n\n" % (s, "#" * encoding.colwidth(s)))
 
     # print options
     section(_("Options"))
@@ -74,7 +79,7 @@
 
     # print cmds
     section(_("Commands"))
-    commandprinter(ui, table)
+    commandprinter(ui, table, subsection)
 
     # print topics
     for names, sec, doc in helptable:
@@ -87,7 +92,25 @@
         ui.write(doc)
         ui.write("\n")
 
-def commandprinter(ui, cmdtable):
+    section(_("Extensions"))
+    ui.write(_("This section contains help for extensions that is distributed "
+               "together with Mercurial. Help for other extensions is available "
+               "in the help system."))
+    ui.write("\n\n"
+             ".. contents::\n"
+             "   :class: htmlonly\n"
+             "   :local:\n"
+             "   :depth: 1\n\n")
+
+    for extensionname in sorted(allextensionnames()):
+        mod = extensions.load(None, extensionname, None)
+        subsection(extensionname)
+        ui.write("%s\n\n" % mod.__doc__)
+        if hasattr(mod, 'cmdtable'):
+            subsubsection(_('Commands'))
+            commandprinter(ui, getattr(mod, 'cmdtable'), subsubsubsection)
+
+def commandprinter(ui, cmdtable, sectionfunc):
     h = {}
     for c, attr in cmdtable.items():
         f = c.split("|")[0]
@@ -124,5 +147,17 @@
             ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
 
 
+def allextensionnames():
+    extensionnames = []
+
+    extensionsdictionary = extensions.enabled()[0]
+    extensionnames.extend(extensionsdictionary.keys())
+
+    extensionsdictionary = extensions.disabled()[0]
+    extensionnames.extend(extensionsdictionary.keys())
+
+    return extensionnames
+
+
 if __name__ == "__main__":
     show_doc(sys.stdout)
diff -r 51031203fc17 -r 905b4645bfb8 doc/hg.1.txt
--- a/doc/hg.1.txt	Tue Oct 19 13:50:03 2010 +0200
+++ b/doc/hg.1.txt	Wed Oct 20 17:45:09 2010 +0200
@@ -14,6 +14,7 @@
 .. contents::
    :backlinks: top
    :class: htmlonly
+   :depth: 1
 
 
 Synopsis


More information about the Mercurial-devel mailing list