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