changeset 12756:13f0acfa974a

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.
author Erik Zielke <ez@aragost.com>
date Mon, 18 Oct 2010 14:37:52 +0200
parents db79d3627872
children 62c8f7691bc3
files doc/gendoc.py
diffstat 1 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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)