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