Patchwork [3,of,5,V3] gendoc: dispatch print document content by commandline arguments

login
register
mail settings
Submitter Takumi IINO
Date July 3, 2013, 1:20 p.m.
Message ID <7d62a614cafbf11f33ac.1372857652@iino-no-MacBook-Air.local>
Download mbox | patch
Permalink /patch/1787/
State Accepted
Commit 81fbd4e66ff502996a01b87cb21407e1d31fad3b
Headers show

Comments

Takumi IINO - July 3, 2013, 1:20 p.m.
# HG changeset patch
# User Takumi IINO <trot.thunder@gmail.com>
# Date 1372855781 -32400
#      Wed Jul 03 21:49:41 2013 +0900
# Node ID 7d62a614cafbf11f33ac21e9d0c24b13d37ea574
# Parent  7cca229fc44fb384b847344b35e7125a1f21476a
gendoc: dispatch print document content by commandline arguments

Before this patch, gendoc.py only prints hg.1.gendoc.txt content.
This adds any content print function.

Patch

diff --git a/doc/Makefile b/doc/Makefile
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -22,7 +22,7 @@ 
 	touch hg.1.txt
 
 hg.1.gendoc.txt: $(GENDOC)
-	${PYTHON} gendoc.py > $@.tmp
+	${PYTHON} gendoc.py hg.1.gendoc > $@.tmp
 	mv $@.tmp $@
 
 hgrc.5: ../mercurial/help/config.txt
diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -1,3 +1,8 @@ 
+"""usage: %s DOC ...
+
+where DOC is the name of a document
+"""
+
 import os, sys, textwrap
 # import from the live mercurial repo
 sys.path.insert(0, "..")
@@ -168,4 +173,12 @@ 
     return extensions.enabled().keys() + extensions.disabled().keys()
 
 if __name__ == "__main__":
-    showdoc(sys.stdout)
+    if len(sys.argv) < 2:
+        sys.stderr.write(__doc__ % sys.argv[0])
+        sys.exit(1)
+
+    doc = sys.argv[1]
+    if doc == 'hg.1.gendoc':
+        showdoc(sys.stdout)
+    else:
+        showtopic(sys.stdout, sys.argv[1])