[PATCH 1 of 3] gendoc: refactor to writing a simple command out in one function

Erik Zielke ez at aragost.com
Fri Oct 22 03:39:22 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1287735680 -7200
# Node ID cb28fd6467c4985fddb91c298ac9886830edf201
# Parent  6bf8d48bec8e1ab2e0462ce14a914d06e64f7117
gendoc: refactor to writing a simple command out in one function.

Extracted the code to print the single command to one function. This
is done, because it is useful to have the restructured text of a
single command other places.

diff -r 6bf8d48bec8e -r cb28fd6467c4 doc/gendoc.py
--- a/doc/gendoc.py	Wed Oct 20 23:48:33 2010 +0200
+++ b/doc/gendoc.py	Fri Oct 22 10:21:20 2010 +0200
@@ -83,7 +83,7 @@
 
     # print cmds
     section(ui, _("Commands"))
-    commandprinter(ui, table, subsection)
+    commandsprinter(ui, table, subsection)
 
     # print topics
     for names, sec, doc in helptable:
@@ -113,9 +113,9 @@
         cmdtable = getattr(mod, 'cmdtable', None)
         if cmdtable:
             subsubsection(ui, _('Commands'))
-            commandprinter(ui, cmdtable, subsubsubsection)
+            commandsprinter(ui, cmdtable, subsubsubsection)
 
-def commandprinter(ui, cmdtable, sectionfunc):
+def commandsprinter(ui, cmdtable, sectionfunc):
     h = {}
     for c, attr in cmdtable.items():
         f = c.split("|")[0]
@@ -129,26 +129,30 @@
             continue
         d = get_cmd(h[f], cmdtable)
         sectionfunc(ui, d['cmd'])
+        commandprinter(ui, d)
         # synopsis
-        ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
+
+def commandprinter(ui, cmd):
+    ui.write('')
+    ui.write("``%s``\n" % cmd['synopsis'].replace("hg ","", 1))
+    ui.write("\n")
+    # description
+    ui.write("%s\n\n" % cmd['desc'][1])
+    # options
+    opt_output = list(cmd['opts'])
+    if opt_output:
+        opts_len = max([len(line[0]) for line in opt_output])
+        ui.write(_("options:\n\n"))
+        for optstr, desc in opt_output:
+            if desc:
+                s = "%-*s  %s" % (opts_len, optstr, desc)
+            else:
+                s = optstr
+            ui.write("%s\n" % s)
         ui.write("\n")
-        # description
-        ui.write("%s\n\n" % d['desc'][1])
-        # options
-        opt_output = list(d['opts'])
-        if opt_output:
-            opts_len = max([len(line[0]) for line in opt_output])
-            ui.write(_("options:\n\n"))
-            for optstr, desc in opt_output:
-                if desc:
-                    s = "%-*s  %s" % (opts_len, optstr, desc)
-                else:
-                    s = optstr
-                ui.write("%s\n" % s)
-            ui.write("\n")
-        # aliases
-        if d['aliases']:
-            ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
+    # aliases
+    if cmd['aliases']:
+        ui.write(_("aliases: %s\n\n") % " ".join(cmd['aliases']))
 
 
 def allextensionnames():


More information about the Mercurial-devel mailing list