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