Patchwork [2,of,9,STABLE?,V2] gendoc: extract print help topics into a dedicated function

login
register
mail settings
Submitter Takumi IINO
Date May 15, 2013, 7:14 a.m.
Message ID <8ef73a60dc14d96a7dbd.1368602059@iino-no-MacBook-Air.local>
Download mbox | patch
Permalink /patch/1643/
State Accepted
Commit 81d9a7f6f2e77f968dd26b0698b85e7abaf7778d
Headers show

Comments

Takumi IINO - May 15, 2013, 7:14 a.m.
# HG changeset patch
# User Takumi IINO <trot.thunder@gmail.com>
# Date 1368600299 -32400
#      Wed May 15 15:44:59 2013 +0900
# Branch stable
# Node ID 8ef73a60dc14d96a7dbd8844df862a51517630f3
# Parent  911aa900c65f42efb5c609c502d038f3acb8cc07
gendoc: extract print help topics into a dedicated function

This will be used in an upcoming patch.
Matt Mackall - May 23, 2013, 10:43 p.m.
On Wed, 2013-05-15 at 16:14 +0900, Takumi IINO wrote:
> # HG changeset patch
> # User Takumi IINO <trot.thunder@gmail.com>
> # Date 1368600299 -32400
> #      Wed May 15 15:44:59 2013 +0900
> # Branch stable
> # Node ID 8ef73a60dc14d96a7dbd8844df862a51517630f3
> # Parent  911aa900c65f42efb5c609c502d038f3acb8cc07
> gendoc: extract print help topics into a dedicated function
> 
> This will be used in an upcoming patch.

I've queued these first two to default, thanks.

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -74,20 +74,9 @@ 
     ui.write(minirst.section(_("Commands")))
     commandprinter(ui, table, minirst.subsection)
 
-    # print topics
-    for names, sec, doc in helptable:
-        if names[0] == "config":
-            # The config help topic is included in the hgrc.5 man
-            # page.
-            continue
-        for name in names:
-            ui.write(".. _%s:\n" % name)
-        ui.write("\n")
-        ui.write(minirst.section(sec))
-        if util.safehasattr(doc, '__call__'):
-            doc = doc()
-        ui.write(doc)
-        ui.write("\n")
+    # print help topics
+    # The config help topic is included in the hgrc.5 man page.
+    helpprinter(ui, helptable, minirst.section, exclude=['config'])
 
     ui.write(minirst.section(_("Extensions")))
     ui.write(_("This section contains help for extensions that are "
@@ -108,6 +97,22 @@ 
             ui.write(minirst.subsubsection(_('Commands')))
             commandprinter(ui, cmdtable, minirst.subsubsubsection)
 
+def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]):
+    for names, sec, doc in helptable:
+        if exclude and names[0] in exclude:
+            continue
+        if include and names[0] not in include:
+            continue
+        for name in names:
+            ui.write(".. _%s:\n" % name)
+        ui.write("\n")
+        if sectionfunc:
+            ui.write(sectionfunc(sec))
+        if util.safehasattr(doc, '__call__'):
+            doc = doc()
+        ui.write(doc)
+        ui.write("\n")
+
 def commandprinter(ui, cmdtable, sectionfunc):
     h = {}
     for c, attr in cmdtable.items():