Show More
@@ -1,125 +1,129 | |||
|
1 | import os, sys | |
|
1 | import os, sys, textwrap | |
|
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 |
desc = |
|
|
24 | desc = shortdesc | |
|
25 | ||
|
26 | desc = textwrap.dedent(desc) | |
|
27 | ||
|
25 | 28 | return (shortdesc, desc) |
|
26 | 29 | |
|
27 | 30 | def get_opts(opts): |
|
28 | 31 | for opt in opts: |
|
29 | 32 | if len(opt) == 5: |
|
30 | 33 | shortopt, longopt, default, desc, optlabel = opt |
|
31 | 34 | else: |
|
32 | 35 | shortopt, longopt, default, desc = opt |
|
33 | 36 | allopts = [] |
|
34 | 37 | if shortopt: |
|
35 | 38 | allopts.append("-%s" % shortopt) |
|
36 | 39 | if longopt: |
|
37 | 40 | allopts.append("--%s" % longopt) |
|
38 | 41 | desc += default and _(" (default: %s)") % default or "" |
|
39 | 42 | yield(", ".join(allopts), desc) |
|
40 | 43 | |
|
41 | 44 | def get_cmd(cmd, cmdtable): |
|
42 | 45 | d = {} |
|
43 | 46 | attr = cmdtable[cmd] |
|
44 | 47 | cmds = cmd.lstrip("^").split("|") |
|
45 | 48 | |
|
46 | 49 | d['cmd'] = cmds[0] |
|
47 | 50 | d['aliases'] = cmd.split("|")[1:] |
|
48 | 51 | d['desc'] = get_desc(attr[0].__doc__) |
|
49 | 52 | d['opts'] = list(get_opts(attr[1])) |
|
50 | 53 | |
|
51 | 54 | s = 'hg ' + cmds[0] |
|
52 | 55 | if len(attr) > 2: |
|
53 | 56 | if not attr[2].startswith('hg'): |
|
54 | 57 | s += ' ' + attr[2] |
|
55 | 58 | else: |
|
56 | 59 | s = attr[2] |
|
57 | 60 | d['synopsis'] = s.strip() |
|
58 | 61 | |
|
59 | 62 | return d |
|
60 | 63 | |
|
61 | 64 | def section(ui, s): |
|
62 | 65 | ui.write("%s\n%s\n\n" % (s, "-" * encoding.colwidth(s))) |
|
63 | 66 | |
|
64 | 67 | def subsection(ui, s): |
|
65 | 68 | ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s))) |
|
66 | 69 | |
|
67 | 70 | |
|
68 | 71 | def show_doc(ui): |
|
69 | 72 | # print options |
|
70 | 73 | section(ui, _("Options")) |
|
71 | 74 | for optstr, desc in get_opts(globalopts): |
|
72 | 75 |
ui.write("%s\n |
|
73 | 76 | |
|
74 | 77 | # print cmds |
|
75 | 78 | section(ui, _("Commands")) |
|
76 | 79 | commandprinter(ui, table) |
|
77 | 80 | |
|
78 | 81 | # print topics |
|
79 | 82 | for names, sec, doc in helptable: |
|
80 | 83 | for name in names: |
|
81 | 84 | ui.write(".. _%s:\n" % name) |
|
82 | 85 | ui.write("\n") |
|
83 | 86 | section(ui, sec) |
|
84 | 87 | if hasattr(doc, '__call__'): |
|
85 | 88 | doc = doc() |
|
86 | 89 | ui.write(doc) |
|
87 | 90 | ui.write("\n") |
|
88 | 91 | |
|
89 | 92 | def commandprinter(ui, cmdtable): |
|
90 | 93 | h = {} |
|
91 | 94 | for c, attr in cmdtable.items(): |
|
92 | 95 | f = c.split("|")[0] |
|
93 | 96 | f = f.lstrip("^") |
|
94 | 97 | h[f] = c |
|
95 | 98 | cmds = h.keys() |
|
96 | 99 | cmds.sort() |
|
97 | 100 | |
|
98 | 101 | for f in cmds: |
|
99 | 102 | if f.startswith("debug"): |
|
100 | 103 | continue |
|
101 | 104 | d = get_cmd(h[f], cmdtable) |
|
102 | 105 | subsection(ui, d['cmd']) |
|
103 | 106 | # synopsis |
|
104 | 107 | ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1)) |
|
108 | ui.write("\n") | |
|
105 | 109 | # description |
|
106 | 110 | ui.write("%s\n\n" % d['desc'][1]) |
|
107 | 111 | # options |
|
108 | 112 | opt_output = list(d['opts']) |
|
109 | 113 | if opt_output: |
|
110 | 114 | opts_len = max([len(line[0]) for line in opt_output]) |
|
111 | 115 |
ui.write(_(" |
|
112 | 116 | for optstr, desc in opt_output: |
|
113 | 117 | if desc: |
|
114 | 118 | s = "%-*s %s" % (opts_len, optstr, desc) |
|
115 | 119 | else: |
|
116 | 120 | s = optstr |
|
117 | 121 |
ui.write(" |
|
118 | 122 | ui.write("\n") |
|
119 | 123 | # aliases |
|
120 | 124 | if d['aliases']: |
|
121 | 125 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) |
|
122 | 126 | |
|
123 | 127 | |
|
124 | 128 | if __name__ == "__main__": |
|
125 | 129 | show_doc(sys.stdout) |
General Comments 0
You need to be logged in to leave comments.
Login now