comparison doc/gendoc.py @ 20081:93f9d11603d8

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 ">".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 08 Nov 2013 14:42:09 +0900
parents 81fbd4e66ff5
children 37f3be9d1541
comparison
equal deleted inserted replaced
20080:c845b1a95eed 20081:93f9d11603d8
38 for opt in opts: 38 for opt in opts:
39 if len(opt) == 5: 39 if len(opt) == 5:
40 shortopt, longopt, default, desc, optlabel = opt 40 shortopt, longopt, default, desc, optlabel = opt
41 else: 41 else:
42 shortopt, longopt, default, desc = opt 42 shortopt, longopt, default, desc = opt
43 optlabel = _("VALUE")
43 allopts = [] 44 allopts = []
44 if shortopt: 45 if shortopt:
45 allopts.append("-%s" % shortopt) 46 allopts.append("-%s" % shortopt)
46 if longopt: 47 if longopt:
47 allopts.append("--%s" % longopt) 48 allopts.append("--%s" % longopt)
49 if isinstance(default, list):
50 allopts[-1] += " <%s[+]>" % optlabel
51 elif (default is not None) and not isinstance(default, bool):
52 allopts[-1] += " <%s>" % optlabel
48 desc += default and _(" (default: %s)") % default or "" 53 desc += default and _(" (default: %s)") % default or ""
49 yield (", ".join(allopts), desc) 54 yield (", ".join(allopts), desc)
50 55
51 def get_cmd(cmd, cmdtable): 56 def get_cmd(cmd, cmdtable):
52 d = {} 57 d = {}
69 return d 74 return d
70 75
71 def showdoc(ui): 76 def showdoc(ui):
72 # print options 77 # print options
73 ui.write(minirst.section(_("Options"))) 78 ui.write(minirst.section(_("Options")))
79 multioccur = False
74 for optstr, desc in get_opts(globalopts): 80 for optstr, desc in get_opts(globalopts):
75 ui.write("%s\n %s\n\n" % (optstr, desc)) 81 ui.write("%s\n %s\n\n" % (optstr, desc))
82 if optstr.endswith("[+]>"):
83 multioccur = True
84 if multioccur:
85 ui.write(_("\n[+] marked option can be specified multiple times\n"))
86 ui.write("\n")
76 87
77 # print cmds 88 # print cmds
78 ui.write(minirst.section(_("Commands"))) 89 ui.write(minirst.section(_("Commands")))
79 commandprinter(ui, table, minirst.subsection) 90 commandprinter(ui, table, minirst.subsection)
80 91
155 # options 166 # options
156 opt_output = list(d['opts']) 167 opt_output = list(d['opts'])
157 if opt_output: 168 if opt_output:
158 opts_len = max([len(line[0]) for line in opt_output]) 169 opts_len = max([len(line[0]) for line in opt_output])
159 ui.write(_("Options:\n\n")) 170 ui.write(_("Options:\n\n"))
171 multioccur = False
160 for optstr, desc in opt_output: 172 for optstr, desc in opt_output:
161 if desc: 173 if desc:
162 s = "%-*s %s" % (opts_len, optstr, desc) 174 s = "%-*s %s" % (opts_len, optstr, desc)
163 else: 175 else:
164 s = optstr 176 s = optstr
165 ui.write("%s\n" % s) 177 ui.write("%s\n" % s)
178 if optstr.endswith("[+]>"):
179 multioccur = True
180 if multioccur:
181 ui.write(_("\n[+] marked option can be specified"
182 " multiple times\n"))
166 ui.write("\n") 183 ui.write("\n")
167 # aliases 184 # aliases
168 if d['aliases']: 185 if d['aliases']:
169 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) 186 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
170 187