Show More
@@ -1,55 +1,55 | |||
|
1 | 1 | SOURCES=$(wildcard *.[0-9].txt) |
|
2 | 2 | MAN=$(SOURCES:%.txt=%) |
|
3 | 3 | HTML=$(SOURCES:%.txt=%.html) |
|
4 | 4 | GENDOC=gendoc.py ../mercurial/commands.py ../mercurial/help.py \ |
|
5 | 5 | ../mercurial/help/*.txt ../hgext/*.py ../hgext/*/__init__.py |
|
6 | 6 | PREFIX=/usr/local |
|
7 | 7 | MANDIR=$(PREFIX)/share/man |
|
8 | 8 | INSTALL=install -c -m 644 |
|
9 | 9 | PYTHON=python |
|
10 | 10 | RSTARGS= |
|
11 | 11 | |
|
12 | 12 | export LANGUAGE=C |
|
13 | 13 | export LC_ALL=C |
|
14 | 14 | |
|
15 | 15 | all: man html |
|
16 | 16 | |
|
17 | 17 | man: $(MAN) |
|
18 | 18 | |
|
19 | 19 | html: $(HTML) |
|
20 | 20 | |
|
21 | 21 | hg.1.txt: hg.1.gendoc.txt |
|
22 | 22 | touch hg.1.txt |
|
23 | 23 | |
|
24 | 24 | hg.1.gendoc.txt: $(GENDOC) |
|
25 | ${PYTHON} gendoc.py > $@.tmp | |
|
25 | ${PYTHON} gendoc.py hg.1.gendoc > $@.tmp | |
|
26 | 26 | mv $@.tmp $@ |
|
27 | 27 | |
|
28 | 28 | hgrc.5: ../mercurial/help/config.txt |
|
29 | 29 | |
|
30 | 30 | hgrc.5.html: ../mercurial/help/config.txt |
|
31 | 31 | |
|
32 | 32 | %: %.txt common.txt |
|
33 | 33 | $(PYTHON) runrst hgmanpage $(RSTARGS) --halt warning \ |
|
34 | 34 | --strip-elements-with-class htmlonly $*.txt $* |
|
35 | 35 | |
|
36 | 36 | %.html: %.txt common.txt |
|
37 | 37 | $(PYTHON) runrst html $(RSTARGS) --halt warning \ |
|
38 | 38 | --link-stylesheet --stylesheet-path style.css $*.txt $*.html |
|
39 | 39 | |
|
40 | 40 | MANIFEST: man html |
|
41 | 41 | # tracked files are already in the main MANIFEST |
|
42 | 42 | $(RM) $@ |
|
43 | 43 | for i in $(MAN) $(HTML); do \ |
|
44 | 44 | echo "doc/$$i" >> $@ ; \ |
|
45 | 45 | done |
|
46 | 46 | |
|
47 | 47 | install: man |
|
48 | 48 | for i in $(MAN) ; do \ |
|
49 | 49 | subdir=`echo $$i | sed -n 's/^.*\.\([0-9]\)$$/man\1/p'` ; \ |
|
50 | 50 | mkdir -p $(DESTDIR)$(MANDIR)/$$subdir ; \ |
|
51 | 51 | $(INSTALL) $$i $(DESTDIR)$(MANDIR)/$$subdir ; \ |
|
52 | 52 | done |
|
53 | 53 | |
|
54 | 54 | clean: |
|
55 | 55 | $(RM) $(MAN) $(HTML) hg.1.gendoc.txt MANIFEST |
@@ -1,171 +1,183 | |||
|
1 | """usage: %s DOC ... | |
|
2 | ||
|
3 | where DOC is the name of a document | |
|
4 | """ | |
|
5 | ||
|
1 | 6 | import os, sys, textwrap |
|
2 | 7 | # import from the live mercurial repo |
|
3 | 8 | sys.path.insert(0, "..") |
|
4 | 9 | # fall back to pure modules if required C extensions are not available |
|
5 | 10 | sys.path.append(os.path.join('..', 'mercurial', 'pure')) |
|
6 | 11 | from mercurial import demandimport; demandimport.enable() |
|
7 | 12 | from mercurial import minirst |
|
8 | 13 | from mercurial.commands import table, globalopts |
|
9 | 14 | from mercurial.i18n import gettext, _ |
|
10 | 15 | from mercurial.help import helptable, loaddoc |
|
11 | 16 | from mercurial import extensions |
|
12 | 17 | from mercurial import util |
|
13 | 18 | |
|
14 | 19 | def get_desc(docstr): |
|
15 | 20 | if not docstr: |
|
16 | 21 | return "", "" |
|
17 | 22 | # sanitize |
|
18 | 23 | docstr = docstr.strip("\n") |
|
19 | 24 | docstr = docstr.rstrip() |
|
20 | 25 | shortdesc = docstr.splitlines()[0].strip() |
|
21 | 26 | |
|
22 | 27 | i = docstr.find("\n") |
|
23 | 28 | if i != -1: |
|
24 | 29 | desc = docstr[i + 2:] |
|
25 | 30 | else: |
|
26 | 31 | desc = shortdesc |
|
27 | 32 | |
|
28 | 33 | desc = textwrap.dedent(desc) |
|
29 | 34 | |
|
30 | 35 | return (shortdesc, desc) |
|
31 | 36 | |
|
32 | 37 | def get_opts(opts): |
|
33 | 38 | for opt in opts: |
|
34 | 39 | if len(opt) == 5: |
|
35 | 40 | shortopt, longopt, default, desc, optlabel = opt |
|
36 | 41 | else: |
|
37 | 42 | shortopt, longopt, default, desc = opt |
|
38 | 43 | allopts = [] |
|
39 | 44 | if shortopt: |
|
40 | 45 | allopts.append("-%s" % shortopt) |
|
41 | 46 | if longopt: |
|
42 | 47 | allopts.append("--%s" % longopt) |
|
43 | 48 | desc += default and _(" (default: %s)") % default or "" |
|
44 | 49 | yield (", ".join(allopts), desc) |
|
45 | 50 | |
|
46 | 51 | def get_cmd(cmd, cmdtable): |
|
47 | 52 | d = {} |
|
48 | 53 | attr = cmdtable[cmd] |
|
49 | 54 | cmds = cmd.lstrip("^").split("|") |
|
50 | 55 | |
|
51 | 56 | d['cmd'] = cmds[0] |
|
52 | 57 | d['aliases'] = cmd.split("|")[1:] |
|
53 | 58 | d['desc'] = get_desc(gettext(attr[0].__doc__)) |
|
54 | 59 | d['opts'] = list(get_opts(attr[1])) |
|
55 | 60 | |
|
56 | 61 | s = 'hg ' + cmds[0] |
|
57 | 62 | if len(attr) > 2: |
|
58 | 63 | if not attr[2].startswith('hg'): |
|
59 | 64 | s += ' ' + attr[2] |
|
60 | 65 | else: |
|
61 | 66 | s = attr[2] |
|
62 | 67 | d['synopsis'] = s.strip() |
|
63 | 68 | |
|
64 | 69 | return d |
|
65 | 70 | |
|
66 | 71 | def showdoc(ui): |
|
67 | 72 | # print options |
|
68 | 73 | ui.write(minirst.section(_("Options"))) |
|
69 | 74 | for optstr, desc in get_opts(globalopts): |
|
70 | 75 | ui.write("%s\n %s\n\n" % (optstr, desc)) |
|
71 | 76 | |
|
72 | 77 | # print cmds |
|
73 | 78 | ui.write(minirst.section(_("Commands"))) |
|
74 | 79 | commandprinter(ui, table, minirst.subsection) |
|
75 | 80 | |
|
76 | 81 | # print help topics |
|
77 | 82 | # The config help topic is included in the hgrc.5 man page. |
|
78 | 83 | helpprinter(ui, helptable, minirst.section, exclude=['config']) |
|
79 | 84 | |
|
80 | 85 | ui.write(minirst.section(_("Extensions"))) |
|
81 | 86 | ui.write(_("This section contains help for extensions that are " |
|
82 | 87 | "distributed together with Mercurial. Help for other " |
|
83 | 88 | "extensions is available in the help system.")) |
|
84 | 89 | ui.write("\n\n" |
|
85 | 90 | ".. contents::\n" |
|
86 | 91 | " :class: htmlonly\n" |
|
87 | 92 | " :local:\n" |
|
88 | 93 | " :depth: 1\n\n") |
|
89 | 94 | |
|
90 | 95 | for extensionname in sorted(allextensionnames()): |
|
91 | 96 | mod = extensions.load(None, extensionname, None) |
|
92 | 97 | ui.write(minirst.subsection(extensionname)) |
|
93 | 98 | ui.write("%s\n\n" % gettext(mod.__doc__)) |
|
94 | 99 | cmdtable = getattr(mod, 'cmdtable', None) |
|
95 | 100 | if cmdtable: |
|
96 | 101 | ui.write(minirst.subsubsection(_('Commands'))) |
|
97 | 102 | commandprinter(ui, cmdtable, minirst.subsubsubsection) |
|
98 | 103 | |
|
99 | 104 | def showtopic(ui, topic): |
|
100 | 105 | extrahelptable = [ |
|
101 | 106 | (["common"], '', loaddoc('common')), |
|
102 | 107 | (["hg.1"], '', loaddoc('hg.1')), |
|
103 | 108 | (["hgignore.5"], '', loaddoc('hgignore.5')), |
|
104 | 109 | (["hgrc.5"], '', loaddoc('hgrc.5')), |
|
105 | 110 | (["hgignore.5.gendoc"], '', loaddoc('hgignore')), |
|
106 | 111 | (["hgrc.5.gendoc"], '', loaddoc('config')), |
|
107 | 112 | ] |
|
108 | 113 | helpprinter(ui, helptable + extrahelptable, None, include=[topic]) |
|
109 | 114 | |
|
110 | 115 | def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): |
|
111 | 116 | for names, sec, doc in helptable: |
|
112 | 117 | if exclude and names[0] in exclude: |
|
113 | 118 | continue |
|
114 | 119 | if include and names[0] not in include: |
|
115 | 120 | continue |
|
116 | 121 | for name in names: |
|
117 | 122 | ui.write(".. _%s:\n" % name) |
|
118 | 123 | ui.write("\n") |
|
119 | 124 | if sectionfunc: |
|
120 | 125 | ui.write(sectionfunc(sec)) |
|
121 | 126 | if util.safehasattr(doc, '__call__'): |
|
122 | 127 | doc = doc() |
|
123 | 128 | ui.write(doc) |
|
124 | 129 | ui.write("\n") |
|
125 | 130 | |
|
126 | 131 | def commandprinter(ui, cmdtable, sectionfunc): |
|
127 | 132 | h = {} |
|
128 | 133 | for c, attr in cmdtable.items(): |
|
129 | 134 | f = c.split("|")[0] |
|
130 | 135 | f = f.lstrip("^") |
|
131 | 136 | h[f] = c |
|
132 | 137 | cmds = h.keys() |
|
133 | 138 | cmds.sort() |
|
134 | 139 | |
|
135 | 140 | for f in cmds: |
|
136 | 141 | if f.startswith("debug"): |
|
137 | 142 | continue |
|
138 | 143 | d = get_cmd(h[f], cmdtable) |
|
139 | 144 | ui.write(sectionfunc(d['cmd'])) |
|
140 | 145 | # synopsis |
|
141 | 146 | ui.write("::\n\n") |
|
142 | 147 | synopsislines = d['synopsis'].splitlines() |
|
143 | 148 | for line in synopsislines: |
|
144 | 149 | # some commands (such as rebase) have a multi-line |
|
145 | 150 | # synopsis |
|
146 | 151 | ui.write(" %s\n" % line) |
|
147 | 152 | ui.write('\n') |
|
148 | 153 | # description |
|
149 | 154 | ui.write("%s\n\n" % d['desc'][1]) |
|
150 | 155 | # options |
|
151 | 156 | opt_output = list(d['opts']) |
|
152 | 157 | if opt_output: |
|
153 | 158 | opts_len = max([len(line[0]) for line in opt_output]) |
|
154 | 159 | ui.write(_("Options:\n\n")) |
|
155 | 160 | for optstr, desc in opt_output: |
|
156 | 161 | if desc: |
|
157 | 162 | s = "%-*s %s" % (opts_len, optstr, desc) |
|
158 | 163 | else: |
|
159 | 164 | s = optstr |
|
160 | 165 | ui.write("%s\n" % s) |
|
161 | 166 | ui.write("\n") |
|
162 | 167 | # aliases |
|
163 | 168 | if d['aliases']: |
|
164 | 169 | ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) |
|
165 | 170 | |
|
166 | 171 | |
|
167 | 172 | def allextensionnames(): |
|
168 | 173 | return extensions.enabled().keys() + extensions.disabled().keys() |
|
169 | 174 | |
|
170 | 175 | if __name__ == "__main__": |
|
176 | doc = 'hg.1.gendoc' | |
|
177 | if len(sys.argv) > 1: | |
|
178 | doc = sys.argv[1] | |
|
179 | ||
|
180 | if doc == 'hg.1.gendoc': | |
|
171 | 181 | showdoc(sys.stdout) |
|
182 | else: | |
|
183 | showtopic(sys.stdout, sys.argv[1]) |
General Comments 0
You need to be logged in to leave comments.
Login now