Show More
@@ -1,160 +1,160 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 import minirst |
|
7 | from mercurial import minirst | |
8 | from mercurial.commands import table, globalopts |
|
8 | from mercurial.commands import table, globalopts | |
9 | from mercurial.i18n import gettext, _ |
|
9 | from mercurial.i18n import gettext, _ | |
10 | from mercurial.help import helptable |
|
10 | from mercurial.help import helptable | |
11 | from mercurial import extensions |
|
11 | from mercurial import extensions | |
12 | from mercurial import util |
|
12 | from mercurial import util | |
13 |
|
13 | |||
14 | def get_desc(docstr): |
|
14 | def get_desc(docstr): | |
15 | if not docstr: |
|
15 | if not docstr: | |
16 | return "", "" |
|
16 | return "", "" | |
17 | # sanitize |
|
17 | # sanitize | |
18 | docstr = docstr.strip("\n") |
|
18 | docstr = docstr.strip("\n") | |
19 | docstr = docstr.rstrip() |
|
19 | docstr = docstr.rstrip() | |
20 | shortdesc = docstr.splitlines()[0].strip() |
|
20 | shortdesc = docstr.splitlines()[0].strip() | |
21 |
|
21 | |||
22 | i = docstr.find("\n") |
|
22 | i = docstr.find("\n") | |
23 | if i != -1: |
|
23 | if i != -1: | |
24 | desc = docstr[i + 2:] |
|
24 | desc = docstr[i + 2:] | |
25 | else: |
|
25 | else: | |
26 | desc = shortdesc |
|
26 | desc = shortdesc | |
27 |
|
27 | |||
28 | desc = textwrap.dedent(desc) |
|
28 | desc = textwrap.dedent(desc) | |
29 |
|
29 | |||
30 | return (shortdesc, desc) |
|
30 | return (shortdesc, desc) | |
31 |
|
31 | |||
32 | def get_opts(opts): |
|
32 | def get_opts(opts): | |
33 | for opt in opts: |
|
33 | for opt in opts: | |
34 | if len(opt) == 5: |
|
34 | if len(opt) == 5: | |
35 | shortopt, longopt, default, desc, optlabel = opt |
|
35 | shortopt, longopt, default, desc, optlabel = opt | |
36 | else: |
|
36 | else: | |
37 | shortopt, longopt, default, desc = opt |
|
37 | shortopt, longopt, default, desc = opt | |
38 | allopts = [] |
|
38 | allopts = [] | |
39 | if shortopt: |
|
39 | if shortopt: | |
40 | allopts.append("-%s" % shortopt) |
|
40 | allopts.append("-%s" % shortopt) | |
41 | if longopt: |
|
41 | if longopt: | |
42 | allopts.append("--%s" % longopt) |
|
42 | allopts.append("--%s" % longopt) | |
43 | desc += default and _(" (default: %s)") % default or "" |
|
43 | desc += default and _(" (default: %s)") % default or "" | |
44 | yield (", ".join(allopts), desc) |
|
44 | yield (", ".join(allopts), desc) | |
45 |
|
45 | |||
46 | def get_cmd(cmd, cmdtable): |
|
46 | def get_cmd(cmd, cmdtable): | |
47 | d = {} |
|
47 | d = {} | |
48 | attr = cmdtable[cmd] |
|
48 | attr = cmdtable[cmd] | |
49 | cmds = cmd.lstrip("^").split("|") |
|
49 | cmds = cmd.lstrip("^").split("|") | |
50 |
|
50 | |||
51 | d['cmd'] = cmds[0] |
|
51 | d['cmd'] = cmds[0] | |
52 | d['aliases'] = cmd.split("|")[1:] |
|
52 | d['aliases'] = cmd.split("|")[1:] | |
53 | d['desc'] = get_desc(gettext(attr[0].__doc__)) |
|
53 | d['desc'] = get_desc(gettext(attr[0].__doc__)) | |
54 | d['opts'] = list(get_opts(attr[1])) |
|
54 | d['opts'] = list(get_opts(attr[1])) | |
55 |
|
55 | |||
56 | s = 'hg ' + cmds[0] |
|
56 | s = 'hg ' + cmds[0] | |
57 | if len(attr) > 2: |
|
57 | if len(attr) > 2: | |
58 | if not attr[2].startswith('hg'): |
|
58 | if not attr[2].startswith('hg'): | |
59 | s += ' ' + attr[2] |
|
59 | s += ' ' + attr[2] | |
60 | else: |
|
60 | else: | |
61 | s = attr[2] |
|
61 | s = attr[2] | |
62 | d['synopsis'] = s.strip() |
|
62 | d['synopsis'] = s.strip() | |
63 |
|
63 | |||
64 | return d |
|
64 | return d | |
65 |
|
65 | |||
66 |
def show |
|
66 | def showdoc(ui): | |
67 | # print options |
|
67 | # print options | |
68 | ui.write(minirst.section(_("Options"))) |
|
68 | ui.write(minirst.section(_("Options"))) | |
69 | for optstr, desc in get_opts(globalopts): |
|
69 | for optstr, desc in get_opts(globalopts): | |
70 | ui.write("%s\n %s\n\n" % (optstr, desc)) |
|
70 | ui.write("%s\n %s\n\n" % (optstr, desc)) | |
71 |
|
71 | |||
72 | # print cmds |
|
72 | # print cmds | |
73 | ui.write(minirst.section(_("Commands"))) |
|
73 | ui.write(minirst.section(_("Commands"))) | |
74 | commandprinter(ui, table, minirst.subsection) |
|
74 | commandprinter(ui, table, minirst.subsection) | |
75 |
|
75 | |||
76 | # print help topics |
|
76 | # print help topics | |
77 | # The config help topic is included in the hgrc.5 man page. |
|
77 | # The config help topic is included in the hgrc.5 man page. | |
78 | helpprinter(ui, helptable, minirst.section, exclude=['config']) |
|
78 | helpprinter(ui, helptable, minirst.section, exclude=['config']) | |
79 |
|
79 | |||
80 | ui.write(minirst.section(_("Extensions"))) |
|
80 | ui.write(minirst.section(_("Extensions"))) | |
81 | ui.write(_("This section contains help for extensions that are " |
|
81 | ui.write(_("This section contains help for extensions that are " | |
82 | "distributed together with Mercurial. Help for other " |
|
82 | "distributed together with Mercurial. Help for other " | |
83 | "extensions is available in the help system.")) |
|
83 | "extensions is available in the help system.")) | |
84 | ui.write("\n\n" |
|
84 | ui.write("\n\n" | |
85 | ".. contents::\n" |
|
85 | ".. contents::\n" | |
86 | " :class: htmlonly\n" |
|
86 | " :class: htmlonly\n" | |
87 | " :local:\n" |
|
87 | " :local:\n" | |
88 | " :depth: 1\n\n") |
|
88 | " :depth: 1\n\n") | |
89 |
|
89 | |||
90 | for extensionname in sorted(allextensionnames()): |
|
90 | for extensionname in sorted(allextensionnames()): | |
91 | mod = extensions.load(None, extensionname, None) |
|
91 | mod = extensions.load(None, extensionname, None) | |
92 | ui.write(minirst.subsection(extensionname)) |
|
92 | ui.write(minirst.subsection(extensionname)) | |
93 | ui.write("%s\n\n" % gettext(mod.__doc__)) |
|
93 | ui.write("%s\n\n" % gettext(mod.__doc__)) | |
94 | cmdtable = getattr(mod, 'cmdtable', None) |
|
94 | cmdtable = getattr(mod, 'cmdtable', None) | |
95 | if cmdtable: |
|
95 | if cmdtable: | |
96 | ui.write(minirst.subsubsection(_('Commands'))) |
|
96 | ui.write(minirst.subsubsection(_('Commands'))) | |
97 | commandprinter(ui, cmdtable, minirst.subsubsubsection) |
|
97 | commandprinter(ui, cmdtable, minirst.subsubsubsection) | |
98 |
|
98 | |||
99 | def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): |
|
99 | def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): | |
100 | for names, sec, doc in helptable: |
|
100 | for names, sec, doc in helptable: | |
101 | if exclude and names[0] in exclude: |
|
101 | if exclude and names[0] in exclude: | |
102 | continue |
|
102 | continue | |
103 | if include and names[0] not in include: |
|
103 | if include and names[0] not in include: | |
104 | continue |
|
104 | continue | |
105 | for name in names: |
|
105 | for name in names: | |
106 | ui.write(".. _%s:\n" % name) |
|
106 | ui.write(".. _%s:\n" % name) | |
107 | ui.write("\n") |
|
107 | ui.write("\n") | |
108 | if sectionfunc: |
|
108 | if sectionfunc: | |
109 | ui.write(sectionfunc(sec)) |
|
109 | ui.write(sectionfunc(sec)) | |
110 | if util.safehasattr(doc, '__call__'): |
|
110 | if util.safehasattr(doc, '__call__'): | |
111 | doc = doc() |
|
111 | doc = doc() | |
112 | ui.write(doc) |
|
112 | ui.write(doc) | |
113 | ui.write("\n") |
|
113 | ui.write("\n") | |
114 |
|
114 | |||
115 | def commandprinter(ui, cmdtable, sectionfunc): |
|
115 | def commandprinter(ui, cmdtable, sectionfunc): | |
116 | h = {} |
|
116 | h = {} | |
117 | for c, attr in cmdtable.items(): |
|
117 | for c, attr in cmdtable.items(): | |
118 | f = c.split("|")[0] |
|
118 | f = c.split("|")[0] | |
119 | f = f.lstrip("^") |
|
119 | f = f.lstrip("^") | |
120 | h[f] = c |
|
120 | h[f] = c | |
121 | cmds = h.keys() |
|
121 | cmds = h.keys() | |
122 | cmds.sort() |
|
122 | cmds.sort() | |
123 |
|
123 | |||
124 | for f in cmds: |
|
124 | for f in cmds: | |
125 | if f.startswith("debug"): |
|
125 | if f.startswith("debug"): | |
126 | continue |
|
126 | continue | |
127 | d = get_cmd(h[f], cmdtable) |
|
127 | d = get_cmd(h[f], cmdtable) | |
128 | ui.write(sectionfunc(d['cmd'])) |
|
128 | ui.write(sectionfunc(d['cmd'])) | |
129 | # synopsis |
|
129 | # synopsis | |
130 | ui.write("::\n\n") |
|
130 | ui.write("::\n\n") | |
131 | synopsislines = d['synopsis'].splitlines() |
|
131 | synopsislines = d['synopsis'].splitlines() | |
132 | for line in synopsislines: |
|
132 | for line in synopsislines: | |
133 | # some commands (such as rebase) have a multi-line |
|
133 | # some commands (such as rebase) have a multi-line | |
134 | # synopsis |
|
134 | # synopsis | |
135 | ui.write(" %s\n" % line) |
|
135 | ui.write(" %s\n" % line) | |
136 | ui.write('\n') |
|
136 | ui.write('\n') | |
137 | # description |
|
137 | # description | |
138 | ui.write("%s\n\n" % d['desc'][1]) |
|
138 | ui.write("%s\n\n" % d['desc'][1]) | |
139 | # options |
|
139 | # options | |
140 | opt_output = list(d['opts']) |
|
140 | opt_output = list(d['opts']) | |
141 | if opt_output: |
|
141 | if opt_output: | |
142 | opts_len = max([len(line[0]) for line in opt_output]) |
|
142 | opts_len = max([len(line[0]) for line in opt_output]) | |
143 | ui.write(_("Options:\n\n")) |
|
143 | ui.write(_("Options:\n\n")) | |
144 | for optstr, desc in opt_output: |
|
144 | for optstr, desc in opt_output: | |
145 | if desc: |
|
145 | if desc: | |
146 | s = "%-*s %s" % (opts_len, optstr, desc) |
|
146 | s = "%-*s %s" % (opts_len, optstr, desc) | |
147 | else: |
|
147 | else: | |
148 | s = optstr |
|
148 | s = optstr | |
149 | ui.write("%s\n" % s) |
|
149 | ui.write("%s\n" % s) | |
150 | ui.write("\n") |
|
150 | ui.write("\n") | |
151 | # aliases |
|
151 | # aliases | |
152 | if d['aliases']: |
|
152 | if d['aliases']: | |
153 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) |
|
153 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) | |
154 |
|
154 | |||
155 |
|
155 | |||
156 | def allextensionnames(): |
|
156 | def allextensionnames(): | |
157 | return extensions.enabled().keys() + extensions.disabled().keys() |
|
157 | return extensions.enabled().keys() + extensions.disabled().keys() | |
158 |
|
158 | |||
159 | if __name__ == "__main__": |
|
159 | if __name__ == "__main__": | |
160 |
show |
|
160 | showdoc(sys.stdout) |
General Comments 0
You need to be logged in to leave comments.
Login now