Patchwork [RESEND] doc: show details of command options in pages generated by docutils

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 8, 2013, 5:47 a.m.
Message ID <980347154ad5319c82c5.1383889638@juju>
Download mbox | patch
Permalink /patch/2886/
State Accepted
Commit 93f9d11603d89fe9359cb0fae21d49515f011cd0
Headers show

Comments

Katsunori FUJIWARA - Nov. 8, 2013, 5:47 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1383889329 -32400
#      Fri Nov 08 14:42:09 2013 +0900
# Node ID 980347154ad5319c82c5e9597bca7c89236ccd8a
# Parent  8dc6f855f43dbc28b30933f5105df2284f3ba3f0
doc: show details of command options in pages generated by docutils

Before this patch, HTML/man pages generated by docutils don't show
details of each command options, whether it should take argument or
not for example, even though "hg help" does.

This patch shows details of command options as same as "hg help"
shows.

This patch uses "--option <VALUE[+]>" style instead of "--option
<VALUE> [+]" used in output of "hg help", because docutils requires
that option argument strings starts with "<" and ends with ">".
Matt Mackall - Nov. 22, 2013, 9:28 p.m.
On Fri, 2013-11-08 at 14:47 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1383889329 -32400
> #      Fri Nov 08 14:42:09 2013 +0900
> # Node ID 980347154ad5319c82c5e9597bca7c89236ccd8a
> # Parent  8dc6f855f43dbc28b30933f5105df2284f3ba3f0
> doc: show details of command options in pages generated by docutils

Queued for default, thanks.

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -40,11 +40,16 @@ 
             shortopt, longopt, default, desc, optlabel = opt
         else:
             shortopt, longopt, default, desc = opt
+            optlabel = _("VALUE")
         allopts = []
         if shortopt:
             allopts.append("-%s" % shortopt)
         if longopt:
             allopts.append("--%s" % longopt)
+        if isinstance(default, list):
+            allopts[-1] += " <%s[+]>" % optlabel
+        elif (default is not None) and not isinstance(default, bool):
+            allopts[-1] += " <%s>" % optlabel
         desc += default and _(" (default: %s)") % default or ""
         yield (", ".join(allopts), desc)
 
@@ -71,8 +76,14 @@ 
 def showdoc(ui):
     # print options
     ui.write(minirst.section(_("Options")))
+    multioccur = False
     for optstr, desc in get_opts(globalopts):
         ui.write("%s\n    %s\n\n" % (optstr, desc))
+        if optstr.endswith("[+]>"):
+            multioccur = True
+    if multioccur:
+        ui.write(_("\n[+] marked option can be specified multiple times\n"))
+        ui.write("\n")
 
     # print cmds
     ui.write(minirst.section(_("Commands")))
@@ -157,12 +168,18 @@ 
         if opt_output:
             opts_len = max([len(line[0]) for line in opt_output])
             ui.write(_("Options:\n\n"))
+            multioccur = False
             for optstr, desc in opt_output:
                 if desc:
                     s = "%-*s  %s" % (opts_len, optstr, desc)
                 else:
                     s = optstr
                 ui.write("%s\n" % s)
+                if optstr.endswith("[+]>"):
+                    multioccur = True
+            if multioccur:
+                ui.write(_("\n[+] marked option can be specified"
+                           " multiple times\n"))
             ui.write("\n")
         # aliases
         if d['aliases']: