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