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