[PATCH 2 of 6] gendoc: refactor get_cmd

Erik Zielke ez at aragost.com
Mon Oct 18 07:54:03 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1287405472 -7200
# Node ID edcaa552781b55748e625b6a39ff695a25b029a4
# Parent  a6d8f90bf825ccad95ac25f23323233217d41617
gendoc: refactor get_cmd

Refactors the get_cmd to take the table as argument, instad
of just referencing the global table, thereby enabling reuse
for extension command tables.

diff -r a6d8f90bf825 -r edcaa552781b doc/gendoc.py
--- a/doc/gendoc.py	Mon Oct 18 14:37:50 2010 +0200
+++ b/doc/gendoc.py	Mon Oct 18 14:37:52 2010 +0200
@@ -38,9 +38,9 @@
         desc += default and _(" (default: %s)") % default or ""
         yield(", ".join(allopts), desc)
 
-def get_cmd(cmd):
+def get_cmd(cmd, cmdtable):
     d = {}
-    attr = table[cmd]
+    attr = cmdtable[cmd]
     cmds = cmd.lstrip("^").split("|")
 
     d['cmd'] = cmds[0]
@@ -71,8 +71,22 @@
 
     # print cmds
     section(_("Commands"))
+    commandprinter(ui, table)
+
+    # print topics
+    for names, sec, doc in helptable:
+        for name in names:
+            ui.write(".. _%s:\n" % name)
+        ui.write("\n")
+        section(sec)
+        if hasattr(doc, '__call__'):
+            doc = doc()
+        ui.write(doc)
+        ui.write("\n")
+
+def commandprinter(ui, cmdtable):
     h = {}
-    for c, attr in table.items():
+    for c, attr in cmdtable.items():
         f = c.split("|")[0]
         f = f.lstrip("^")
         h[f] = c
@@ -82,7 +96,7 @@
     for f in cmds:
         if f.startswith("debug"):
             continue
-        d = get_cmd(h[f])
+        d = get_cmd(h[f], cmdtable)
         # synopsis
         ui.write(".. _%s:\n\n" % d['cmd'])
         ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
@@ -104,16 +118,6 @@
         if d['aliases']:
             ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
 
-    # print topics
-    for names, sec, doc in helptable:
-        for name in names:
-            ui.write(".. _%s:\n" % name)
-        ui.write("\n")
-        section(sec)
-        if hasattr(doc, '__call__'):
-            doc = doc()
-        ui.write(doc)
-        ui.write("\n")
 
 if __name__ == "__main__":
     show_doc(sys.stdout)


More information about the Mercurial-devel mailing list