##// END OF EJS Templates
gendoc: fix synopsis...
Martin Geisler -
r9622:9d1a480c default
parent child Browse files
Show More
@@ -1,114 +1,114 b''
1 import os, sys
1 import os, sys
2 # import from the live mercurial repo
2 # import from the live mercurial repo
3 sys.path.insert(0, "..")
3 sys.path.insert(0, "..")
4 # fall back to pure modules if required C extensions are not available
4 # fall back to pure modules if required C extensions are not available
5 sys.path.append(os.path.join('..', 'mercurial', 'pure'))
5 sys.path.append(os.path.join('..', 'mercurial', 'pure'))
6 from mercurial import demandimport; demandimport.enable()
6 from mercurial import demandimport; demandimport.enable()
7 from mercurial import encoding
7 from mercurial import encoding
8 from mercurial.commands import table, globalopts
8 from mercurial.commands import table, globalopts
9 from mercurial.i18n import _
9 from mercurial.i18n import _
10 from mercurial.help import helptable
10 from mercurial.help import helptable
11
11
12 def get_desc(docstr):
12 def get_desc(docstr):
13 if not docstr:
13 if not docstr:
14 return "", ""
14 return "", ""
15 # sanitize
15 # sanitize
16 docstr = docstr.strip("\n")
16 docstr = docstr.strip("\n")
17 docstr = docstr.rstrip()
17 docstr = docstr.rstrip()
18 shortdesc = docstr.splitlines()[0].strip()
18 shortdesc = docstr.splitlines()[0].strip()
19
19
20 i = docstr.find("\n")
20 i = docstr.find("\n")
21 if i != -1:
21 if i != -1:
22 desc = docstr[i+2:]
22 desc = docstr[i+2:]
23 else:
23 else:
24 desc = " %s" % shortdesc
24 desc = " %s" % shortdesc
25 return (shortdesc, desc)
25 return (shortdesc, desc)
26
26
27 def get_opts(opts):
27 def get_opts(opts):
28 for shortopt, longopt, default, desc in opts:
28 for shortopt, longopt, default, desc in opts:
29 allopts = []
29 allopts = []
30 if shortopt:
30 if shortopt:
31 allopts.append("-%s" % shortopt)
31 allopts.append("-%s" % shortopt)
32 if longopt:
32 if longopt:
33 allopts.append("--%s" % longopt)
33 allopts.append("--%s" % longopt)
34 desc += default and _(" (default: %s)") % default or ""
34 desc += default and _(" (default: %s)") % default or ""
35 yield(", ".join(allopts), desc)
35 yield(", ".join(allopts), desc)
36
36
37 def get_cmd(cmd):
37 def get_cmd(cmd):
38 d = {}
38 d = {}
39 attr = table[cmd]
39 attr = table[cmd]
40 cmds = cmd.lstrip("^").split("|")
40 cmds = cmd.lstrip("^").split("|")
41
41
42 d['cmd'] = cmds[0]
42 d['cmd'] = cmds[0]
43 d['aliases'] = cmd.split("|")[1:]
43 d['aliases'] = cmd.split("|")[1:]
44 d['desc'] = get_desc(attr[0].__doc__)
44 d['desc'] = get_desc(attr[0].__doc__)
45 d['opts'] = list(get_opts(attr[1]))
45 d['opts'] = list(get_opts(attr[1]))
46
46
47 s = 'hg ' + cmds[0]
47 s = 'hg ' + cmds[0]
48 if len(attr) > 2:
48 if len(attr) > 2:
49 if not attr[2].startswith('hg'):
49 if not attr[2].startswith('hg'):
50 s += ' ' + attr[2]
50 s += ' ' + attr[2]
51 else:
51 else:
52 s = attr[2]
52 s = attr[2]
53 d['synopsis'] = s
53 d['synopsis'] = s.strip()
54
54
55 return d
55 return d
56
56
57 def show_doc(ui):
57 def show_doc(ui):
58 def section(s):
58 def section(s):
59 ui.write("%s\n%s\n\n" % (s, "-" * encoding.colwidth(s)))
59 ui.write("%s\n%s\n\n" % (s, "-" * encoding.colwidth(s)))
60 def subsection(s):
60 def subsection(s):
61 ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s)))
61 ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s)))
62
62
63 # print options
63 # print options
64 section(_("OPTIONS"))
64 section(_("OPTIONS"))
65 for optstr, desc in get_opts(globalopts):
65 for optstr, desc in get_opts(globalopts):
66 ui.write("%s\n %s\n\n" % (optstr, desc))
66 ui.write("%s\n %s\n\n" % (optstr, desc))
67
67
68 # print cmds
68 # print cmds
69 section(_("COMMANDS"))
69 section(_("COMMANDS"))
70 h = {}
70 h = {}
71 for c, attr in table.items():
71 for c, attr in table.items():
72 f = c.split("|")[0]
72 f = c.split("|")[0]
73 f = f.lstrip("^")
73 f = f.lstrip("^")
74 h[f] = c
74 h[f] = c
75 cmds = h.keys()
75 cmds = h.keys()
76 cmds.sort()
76 cmds.sort()
77
77
78 for f in cmds:
78 for f in cmds:
79 if f.startswith("debug"): continue
79 if f.startswith("debug"): continue
80 d = get_cmd(h[f])
80 d = get_cmd(h[f])
81 # synopsis
81 # synopsis
82 ui.write(".. _%s:\n\n" % d['cmd'])
82 ui.write(".. _%s:\n\n" % d['cmd'])
83 ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
83 ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
84 # description
84 # description
85 ui.write("%s\n\n" % d['desc'][1])
85 ui.write("%s\n\n" % d['desc'][1])
86 # options
86 # options
87 opt_output = list(d['opts'])
87 opt_output = list(d['opts'])
88 if opt_output:
88 if opt_output:
89 opts_len = max([len(line[0]) for line in opt_output])
89 opts_len = max([len(line[0]) for line in opt_output])
90 ui.write(_(" options:\n\n"))
90 ui.write(_(" options:\n\n"))
91 for optstr, desc in opt_output:
91 for optstr, desc in opt_output:
92 if desc:
92 if desc:
93 s = "%-*s %s" % (opts_len, optstr, desc)
93 s = "%-*s %s" % (opts_len, optstr, desc)
94 else:
94 else:
95 s = optstr
95 s = optstr
96 ui.write(" %s\n" % s)
96 ui.write(" %s\n" % s)
97 ui.write("\n")
97 ui.write("\n")
98 # aliases
98 # aliases
99 if d['aliases']:
99 if d['aliases']:
100 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
100 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
101
101
102 # print topics
102 # print topics
103 for names, sec, doc in helptable:
103 for names, sec, doc in helptable:
104 for name in names:
104 for name in names:
105 ui.write(".. _%s:\n" % name)
105 ui.write(".. _%s:\n" % name)
106 ui.write("\n")
106 ui.write("\n")
107 section(sec.upper())
107 section(sec.upper())
108 if callable(doc):
108 if callable(doc):
109 doc = doc()
109 doc = doc()
110 ui.write(doc)
110 ui.write(doc)
111 ui.write("\n")
111 ui.write("\n")
112
112
113 if __name__ == "__main__":
113 if __name__ == "__main__":
114 show_doc(sys.stdout)
114 show_doc(sys.stdout)
General Comments 0
You need to be logged in to leave comments. Login now