author | Kyle Lippincott <spectral@google.com> |
Wed, 07 Nov 2018 15:45:09 -0800 | |
changeset 41281 | 183df3df6031 |
parent 41037 | 2eeef8e577ac |
child 42248 | 0786b791b3b5 |
permissions | -rwxr-xr-x |
27496
f22cd17a22e7
doc: add execute bit and fix shbang line for gendoc.py
timeless <timeless@mozdev.org>
parents:
27330
diff
changeset
|
1 |
#!/usr/bin/env python |
19425
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
2 |
"""usage: %s DOC ... |
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
3 |
|
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
4 |
where DOC is the name of a document |
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
5 |
""" |
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
6 |
|
28966
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
7 |
from __future__ import absolute_import |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
8 |
|
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
9 |
import os |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
10 |
import sys |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
11 |
import textwrap |
27330
6fbf1159a85a
doc: make gendoc.py module import policy aware
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26413
diff
changeset
|
12 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
13 |
try: |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
14 |
import msvcrt |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
15 |
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
16 |
msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
17 |
except ImportError: |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
18 |
pass |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
19 |
|
27330
6fbf1159a85a
doc: make gendoc.py module import policy aware
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26413
diff
changeset
|
20 |
# This script is executed during installs and may not have C extensions |
6fbf1159a85a
doc: make gendoc.py module import policy aware
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26413
diff
changeset
|
21 |
# available. Relax C module requirements. |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
22 |
os.environ[r'HGMODULEPOLICY'] = r'allow' |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
23 |
# import from the live mercurial repo |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
24 |
sys.path.insert(0, r"..") |
5209 | 25 |
from mercurial import demandimport; demandimport.enable() |
32336
ff874d34c856
gendoc: make sure locale path is set before loading any modules
Yuya Nishihara <yuya@tcha.org>
parents:
30559
diff
changeset
|
26 |
# Load util so that the locale path is set by i18n.setdatapath() before |
ff874d34c856
gendoc: make sure locale path is set before loading any modules
Yuya Nishihara <yuya@tcha.org>
parents:
30559
diff
changeset
|
27 |
# calling _(). |
ff874d34c856
gendoc: make sure locale path is set before loading any modules
Yuya Nishihara <yuya@tcha.org>
parents:
30559
diff
changeset
|
28 |
from mercurial import util |
ff874d34c856
gendoc: make sure locale path is set before loading any modules
Yuya Nishihara <yuya@tcha.org>
parents:
30559
diff
changeset
|
29 |
util.datapath |
28966
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
30 |
from mercurial import ( |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
31 |
commands, |
41030
c0865f3da285
py3: byteify sys.argv in gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
41004
diff
changeset
|
32 |
encoding, |
28966
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
33 |
extensions, |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
34 |
help, |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
35 |
minirst, |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
36 |
pycompat, |
28966
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
37 |
ui as uimod, |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
38 |
) |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
39 |
from mercurial.i18n import ( |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
40 |
gettext, |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
41 |
_, |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
42 |
) |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
43 |
|
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
44 |
table = commands.table |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
45 |
globalopts = commands.globalopts |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
46 |
helptable = help.helptable |
ea1fab5293ca
py3: make gendoc use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27660
diff
changeset
|
47 |
loaddoc = help.loaddoc |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
48 |
|
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
49 |
def get_desc(docstr): |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
50 |
if not docstr: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
51 |
return b"", b"" |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
52 |
# sanitize |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
53 |
docstr = docstr.strip(b"\n") |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
54 |
docstr = docstr.rstrip() |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
55 |
shortdesc = docstr.splitlines()[0].strip() |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
56 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
57 |
i = docstr.find(b"\n") |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
58 |
if i != -1: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9792
diff
changeset
|
59 |
desc = docstr[i + 2:] |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
60 |
else: |
12780
bdc1cf692447
gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents:
12777
diff
changeset
|
61 |
desc = shortdesc |
bdc1cf692447
gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents:
12777
diff
changeset
|
62 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
63 |
desc = textwrap.dedent(desc.decode('latin1')).encode('latin1') |
12780
bdc1cf692447
gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents:
12777
diff
changeset
|
64 |
|
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
65 |
return (shortdesc, desc) |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
66 |
|
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
67 |
def get_opts(opts): |
11321
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
68 |
for opt in opts: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
69 |
if len(opt) == 5: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
70 |
shortopt, longopt, default, desc, optlabel = opt |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
71 |
else: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
72 |
shortopt, longopt, default, desc = opt |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
73 |
optlabel = _(b"VALUE") |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
74 |
allopts = [] |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
75 |
if shortopt: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
76 |
allopts.append(b"-%s" % shortopt) |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
77 |
if longopt: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
78 |
allopts.append(b"--%s" % longopt) |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
79 |
if isinstance(default, list): |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
80 |
allopts[-1] += b" <%s[+]>" % optlabel |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
81 |
elif (default is not None) and not isinstance(default, bool): |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
82 |
allopts[-1] += b" <%s>" % optlabel |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
83 |
if b'\n' in desc: |
20655
37f3be9d1541
doc: gendoc.py creates valid output for option descriptions with newlines
Simon Heimberg <simohe@besonet.ch>
parents:
20081
diff
changeset
|
84 |
# only remove line breaks and indentation |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
85 |
desc = b' '.join(l.lstrip() for l in desc.split(b'\n')) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
86 |
desc += default and _(b" (default: %s)") % bytes(default) or b"" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
87 |
yield (b", ".join(allopts), desc) |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
88 |
|
12756 | 89 |
def get_cmd(cmd, cmdtable): |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
90 |
d = {} |
12756 | 91 |
attr = cmdtable[cmd] |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
92 |
cmds = cmd.lstrip(b"^").split(b"|") |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
93 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
94 |
d[b'cmd'] = cmds[0] |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
95 |
d[b'aliases'] = cmd.split(b"|")[1:] |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
96 |
d[b'desc'] = get_desc(gettext(pycompat.getdoc(attr[0]))) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
97 |
d[b'opts'] = list(get_opts(attr[1])) |
7376
fc06bd17c985
doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents:
7014
diff
changeset
|
98 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
99 |
s = b'hg ' + cmds[0] |
7376
fc06bd17c985
doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents:
7014
diff
changeset
|
100 |
if len(attr) > 2: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
101 |
if not attr[2].startswith(b'hg'): |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
102 |
s += b' ' + attr[2] |
7376
fc06bd17c985
doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents:
7014
diff
changeset
|
103 |
else: |
fc06bd17c985
doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents:
7014
diff
changeset
|
104 |
s = attr[2] |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
105 |
d[b'synopsis'] = s.strip() |
7376
fc06bd17c985
doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents:
7014
diff
changeset
|
106 |
|
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
107 |
return d |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
108 |
|
19423
5046fede7684
gendoc: rename to showdoc from show_doc
Takumi IINO <trot.thunder@gmail.com>
parents:
19322
diff
changeset
|
109 |
def showdoc(ui): |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
110 |
# print options |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
111 |
ui.write(minirst.section(_(b"Options"))) |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
112 |
multioccur = False |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
113 |
for optstr, desc in get_opts(globalopts): |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
114 |
ui.write(b"%s\n %s\n\n" % (optstr, desc)) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
115 |
if optstr.endswith(b"[+]>"): |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
116 |
multioccur = True |
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
117 |
if multioccur: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
118 |
ui.write(_(b"\n[+] marked option can be specified multiple times\n")) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
119 |
ui.write(b"\n") |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
120 |
|
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
121 |
# print cmds |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
122 |
ui.write(minirst.section(_(b"Commands"))) |
18748
6e676fb6ea44
help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
17267
diff
changeset
|
123 |
commandprinter(ui, table, minirst.subsection) |
12756 | 124 |
|
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
125 |
# print help topics |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
126 |
# The config help topic is included in the hgrc.5 man page. |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
127 |
helpprinter(ui, helptable, minirst.section, exclude=[b'config']) |
12756 | 128 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
129 |
ui.write(minirst.section(_(b"Extensions"))) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
130 |
ui.write(_(b"This section contains help for extensions that are " |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
131 |
b"distributed together with Mercurial. Help for other " |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
132 |
b"extensions is available in the help system.")) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
133 |
ui.write((b"\n\n" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
134 |
b".. contents::\n" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
135 |
b" :class: htmlonly\n" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
136 |
b" :local:\n" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
137 |
b" :depth: 1\n\n")) |
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
138 |
|
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
139 |
for extensionname in sorted(allextensionnames()): |
27660
512f883c234c
mercurial: pass ui to extensions.load (issue5007)
Jun Wu <quark@fb.com>
parents:
27496
diff
changeset
|
140 |
mod = extensions.load(ui, extensionname, None) |
18748
6e676fb6ea44
help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
17267
diff
changeset
|
141 |
ui.write(minirst.subsection(extensionname)) |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
142 |
ui.write(b"%s\n\n" % gettext(pycompat.getdoc(mod))) |
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
143 |
cmdtable = getattr(mod, 'cmdtable', None) |
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
144 |
if cmdtable: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
145 |
ui.write(minirst.subsubsection(_(b'Commands'))) |
18748
6e676fb6ea44
help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
17267
diff
changeset
|
146 |
commandprinter(ui, cmdtable, minirst.subsubsubsection) |
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
147 |
|
19424
762e51ce3411
gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents:
19423
diff
changeset
|
148 |
def showtopic(ui, topic): |
762e51ce3411
gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents:
19423
diff
changeset
|
149 |
extrahelptable = [ |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
150 |
([b"common"], b'', loaddoc(b'common'), help.TOPIC_CATEGORY_MISC), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
151 |
([b"hg.1"], b'', loaddoc(b'hg.1'), help.TOPIC_CATEGORY_CONFIG), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
152 |
([b"hg-ssh.8"], b'', loaddoc(b'hg-ssh.8'), help.TOPIC_CATEGORY_CONFIG), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
153 |
([b"hgignore.5"], b'', loaddoc(b'hgignore.5'), |
40294
fabbf9310025
help: assigning topic categories
Rodrigo Damazio <rdamazio@google.com>
parents:
40291
diff
changeset
|
154 |
help.TOPIC_CATEGORY_CONFIG), |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
155 |
([b"hgrc.5"], b'', loaddoc(b'hgrc.5'), help.TOPIC_CATEGORY_CONFIG), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
156 |
([b"hgignore.5.gendoc"], b'', loaddoc(b'hgignore'), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
157 |
help.TOPIC_CATEGORY_CONFIG), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
158 |
([b"hgrc.5.gendoc"], b'', loaddoc(b'config'), |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
159 |
help.TOPIC_CATEGORY_CONFIG), |
19424
762e51ce3411
gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents:
19423
diff
changeset
|
160 |
] |
762e51ce3411
gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents:
19423
diff
changeset
|
161 |
helpprinter(ui, helptable + extrahelptable, None, include=[topic]) |
762e51ce3411
gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents:
19423
diff
changeset
|
162 |
|
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
163 |
def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]): |
40291
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
32336
diff
changeset
|
164 |
for h in helptable: |
170926caf44c
help: adding support for command categories
rdamazio@google.com
parents:
32336
diff
changeset
|
165 |
names, sec, doc = h[0:3] |
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
166 |
if exclude and names[0] in exclude: |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
167 |
continue |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
168 |
if include and names[0] not in include: |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
169 |
continue |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
170 |
for name in names: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
171 |
ui.write(b".. _%s:\n" % name) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
172 |
ui.write(b"\n") |
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
173 |
if sectionfunc: |
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
174 |
ui.write(sectionfunc(sec)) |
21793
e0b29a0c36c4
gendoc: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
20689
diff
changeset
|
175 |
if callable(doc): |
26413
e0c572d4d112
help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents:
26412
diff
changeset
|
176 |
doc = doc(ui) |
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
177 |
ui.write(doc) |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
178 |
ui.write(b"\n") |
19233
81d9a7f6f2e7
gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents:
19231
diff
changeset
|
179 |
|
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
180 |
def commandprinter(ui, cmdtable, sectionfunc): |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
181 |
h = {} |
12756 | 182 |
for c, attr in cmdtable.items(): |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
183 |
f = c.split(b"|")[0] |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
184 |
f = f.lstrip(b"^") |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
185 |
h[f] = c |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
186 |
cmds = h.keys() |
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
187 |
|
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
188 |
for f in sorted(cmds): |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
189 |
if f.startswith(b"debug"): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
9792
diff
changeset
|
190 |
continue |
12756 | 191 |
d = get_cmd(h[f], cmdtable) |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
192 |
ui.write(sectionfunc(d[b'cmd'])) |
20689
401f9b661a2d
doc: show short description of each commands in generated documents
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20655
diff
changeset
|
193 |
# short description |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
194 |
ui.write(d[b'desc'][0]) |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
195 |
# synopsis |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
196 |
ui.write(b"::\n\n") |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
197 |
synopsislines = d[b'synopsis'].splitlines() |
12813
13fdef670c43
gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents:
12812
diff
changeset
|
198 |
for line in synopsislines: |
13fdef670c43
gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents:
12812
diff
changeset
|
199 |
# some commands (such as rebase) have a multi-line |
13fdef670c43
gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents:
12812
diff
changeset
|
200 |
# synopsis |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
201 |
ui.write(b" %s\n" % line) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
202 |
ui.write(b'\n') |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
203 |
# description |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
204 |
ui.write(b"%s\n\n" % d[b'desc'][1]) |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
205 |
# options |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
206 |
opt_output = list(d[b'opts']) |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
207 |
if opt_output: |
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
208 |
opts_len = max([len(line[0]) for line in opt_output]) |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
209 |
ui.write(_(b"Options:\n\n")) |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
210 |
multioccur = False |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
211 |
for optstr, desc in opt_output: |
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
212 |
if desc: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
213 |
s = b"%-*s %s" % (opts_len, optstr, desc) |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
214 |
else: |
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
215 |
s = optstr |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
216 |
ui.write(b"%s\n" % s) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
217 |
if optstr.endswith(b"[+]>"): |
20081
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
218 |
multioccur = True |
93f9d11603d8
doc: show details of command options in pages generated by docutils
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19425
diff
changeset
|
219 |
if multioccur: |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
220 |
ui.write(_(b"\n[+] marked option can be specified" |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
221 |
b" multiple times\n")) |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
222 |
ui.write(b"\n") |
6488
119dff2cd592
gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents:
5209
diff
changeset
|
223 |
# aliases |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
224 |
if d[b'aliases']: |
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
225 |
ui.write(_(b" aliases: %s\n\n") % b" ".join(d[b'aliases'])) |
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
226 |
|
3797
54fd4d3b4fce
Generate docs for help topics
Matt Mackall <mpm@selenic.com>
parents:
1814
diff
changeset
|
227 |
|
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
228 |
def allextensionnames(): |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
229 |
return set(extensions.enabled().keys()) | set(extensions.disabled().keys()) |
12781
0d09991f91ee
gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents:
12780
diff
changeset
|
230 |
|
1814
7956893e8458
generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
231 |
if __name__ == "__main__": |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
232 |
doc = b'hg.1.gendoc' |
19425
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
233 |
if len(sys.argv) > 1: |
41030
c0865f3da285
py3: byteify sys.argv in gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
41004
diff
changeset
|
234 |
doc = encoding.strtolocal(sys.argv[1]) |
19425
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
235 |
|
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29397
diff
changeset
|
236 |
ui = uimod.ui.load() |
41004
e10641c48fa7
py3: byteify gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
40294
diff
changeset
|
237 |
if doc == b'hg.1.gendoc': |
26412
7e8e3c0920a6
gendoc: use real ui in place of stdout
Yuya Nishihara <yuya@tcha.org>
parents:
21793
diff
changeset
|
238 |
showdoc(ui) |
19425
81fbd4e66ff5
gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents:
19424
diff
changeset
|
239 |
else: |
41037
2eeef8e577ac
py3: byteify one more sys.argv in gendoc.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
41030
diff
changeset
|
240 |
showtopic(ui, encoding.strtolocal(sys.argv[1])) |