doc/gendoc.py
author Takumi IINO <trot.thunder@gmail.com>
Wed, 03 Jul 2013 21:49:41 +0900
changeset 19425 81fbd4e66ff5
parent 19424 762e51ce3411
child 20081 93f9d11603d8
permissions -rw-r--r--
gendoc: dispatch print document content by commandline arguments Before this patch, gendoc.py only prints hg.1.gendoc.txt content. This adds any content print function.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19425
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
     1
"""usage: %s DOC ...
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
     2
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
     3
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
     4
"""
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
     5
12780
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
     6
import os, sys, textwrap
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
     7
# import from the live mercurial repo
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
     8
sys.path.insert(0, "..")
9130
335f749cc369 gendoc: fall back to pure modules if C extensions are not available (issue1711)
Cédric Duval <cedricduval@free.fr>
parents: 9021
diff changeset
     9
# fall back to pure modules if required C extensions are not available
335f749cc369 gendoc: fall back to pure modules if C extensions are not available (issue1711)
Cédric Duval <cedricduval@free.fr>
parents: 9021
diff changeset
    10
sys.path.append(os.path.join('..', 'mercurial', 'pure'))
5209
bbdcdc7f170e gendoc: use demandimport
Matt Mackall <mpm@selenic.com>
parents: 3797
diff changeset
    11
from mercurial import demandimport; demandimport.enable()
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    12
from mercurial import minirst
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    13
from mercurial.commands import table, globalopts
19231
814291b5e79c gendoc: make commnd __doc__ and extension __doc__ as translatable
Takumi IINO <trot.thunder@gmail.com>
parents: 18748
diff changeset
    14
from mercurial.i18n import gettext, _
19424
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
    15
from mercurial.help import helptable, loaddoc
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    16
from mercurial import extensions
14943
d3bb825ddae3 globally: use safehasattr(x, '__call__') instead of hasattr(x, '__call__')
Augie Fackler <durin42@gmail.com>
parents: 14461
diff changeset
    17
from mercurial import util
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    18
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    19
def get_desc(docstr):
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    20
    if not docstr:
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    21
        return "", ""
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    22
    # sanitize
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    23
    docstr = docstr.strip("\n")
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    24
    docstr = docstr.rstrip()
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    25
    shortdesc = docstr.splitlines()[0].strip()
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    26
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    27
    i = docstr.find("\n")
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    28
    if i != -1:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 9792
diff changeset
    29
        desc = docstr[i + 2:]
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    30
    else:
12780
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
    31
        desc = shortdesc
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
    32
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
    33
    desc = textwrap.dedent(desc)
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
    34
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    35
    return (shortdesc, desc)
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    36
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    37
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
    38
    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
    39
        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
    40
            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
    41
        else:
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10282
diff changeset
    42
            shortopt, longopt, default, desc = opt
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    43
        allopts = []
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    44
        if shortopt:
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    45
            allopts.append("-%s" % shortopt)
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    46
        if longopt:
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    47
            allopts.append("--%s" % longopt)
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    48
        desc += default and _(" (default: %s)") % default or ""
13077
6b8d2ee24ce2 coding style: fix yield used as a function
Thomas Arendsen Hein <thomas@jtah.de>
parents: 12814
diff changeset
    49
        yield (", ".join(allopts), desc)
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    50
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
    51
def get_cmd(cmd, cmdtable):
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    52
    d = {}
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
    53
    attr = cmdtable[cmd]
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    54
    cmds = cmd.lstrip("^").split("|")
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    55
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    56
    d['cmd'] = cmds[0]
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    57
    d['aliases'] = cmd.split("|")[1:]
19231
814291b5e79c gendoc: make commnd __doc__ and extension __doc__ as translatable
Takumi IINO <trot.thunder@gmail.com>
parents: 18748
diff changeset
    58
    d['desc'] = get_desc(gettext(attr[0].__doc__))
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    59
    d['opts'] = list(get_opts(attr[1]))
7376
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    60
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    61
    s = 'hg ' + cmds[0]
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    62
    if len(attr) > 2:
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    63
        if not attr[2].startswith('hg'):
8546
a33d19dcf906 gendoc: add missing space in command synopsis
Ori Avtalion <ori@avtalion.name>
parents: 7376
diff changeset
    64
            s += ' ' + attr[2]
7376
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    65
        else:
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    66
            s = attr[2]
9622
9d1a480ca6ea gendoc: fix synopsis
Martin Geisler <mg@lazybytes.net>
parents: 9485
diff changeset
    67
    d['synopsis'] = s.strip()
7376
fc06bd17c985 doc: handle shortened command synopses
Matt Mackall <mpm@selenic.com>
parents: 7014
diff changeset
    68
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    69
    return d
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    70
19423
5046fede7684 gendoc: rename to showdoc from show_doc
Takumi IINO <trot.thunder@gmail.com>
parents: 19322
diff changeset
    71
def showdoc(ui):
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    72
    # print options
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    73
    ui.write(minirst.section(_("Options")))
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    74
    for optstr, desc in get_opts(globalopts):
12812
4d431a31a76e gendoc: re-add indentation to global option table
Martin Geisler <mg@lazybytes.net>
parents: 12804
diff changeset
    75
        ui.write("%s\n    %s\n\n" % (optstr, desc))
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    76
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    77
    # print cmds
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    78
    ui.write(minirst.section(_("Commands")))
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    79
    commandprinter(ui, table, minirst.subsection)
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
    80
19233
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
    81
    # print help topics
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
    82
    # The config help topic is included in the hgrc.5 man page.
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
    83
    helpprinter(ui, helptable, minirst.section, exclude=['config'])
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
    84
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    85
    ui.write(minirst.section(_("Extensions")))
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 14943
diff changeset
    86
    ui.write(_("This section contains help for extensions that are "
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 14943
diff changeset
    87
               "distributed together with Mercurial. Help for other "
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 14943
diff changeset
    88
               "extensions is available in the help system."))
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    89
    ui.write("\n\n"
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    90
             ".. contents::\n"
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    91
             "   :class: htmlonly\n"
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    92
             "   :local:\n"
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    93
             "   :depth: 1\n\n")
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    94
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    95
    for extensionname in sorted(allextensionnames()):
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    96
        mod = extensions.load(None, extensionname, None)
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
    97
        ui.write(minirst.subsection(extensionname))
19231
814291b5e79c gendoc: make commnd __doc__ and extension __doc__ as translatable
Takumi IINO <trot.thunder@gmail.com>
parents: 18748
diff changeset
    98
        ui.write("%s\n\n" % gettext(mod.__doc__))
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
    99
        cmdtable = getattr(mod, 'cmdtable', None)
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
   100
        if cmdtable:
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
   101
            ui.write(minirst.subsubsection(_('Commands')))
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
   102
            commandprinter(ui, cmdtable, minirst.subsubsubsection)
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
   103
19424
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   104
def showtopic(ui, topic):
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   105
    extrahelptable = [
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   106
        (["common"], '', loaddoc('common')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   107
        (["hg.1"], '', loaddoc('hg.1')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   108
        (["hgignore.5"], '', loaddoc('hgignore.5')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   109
        (["hgrc.5"], '', loaddoc('hgrc.5')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   110
        (["hgignore.5.gendoc"], '', loaddoc('hgignore')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   111
        (["hgrc.5.gendoc"], '', loaddoc('config')),
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   112
    ]
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   113
    helpprinter(ui, helptable + extrahelptable, None, include=[topic])
762e51ce3411 gendoc: add showtopic
Takumi IINO <trot.thunder@gmail.com>
parents: 19423
diff changeset
   114
19233
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   115
def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]):
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   116
    for names, sec, doc in helptable:
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   117
        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
   118
            continue
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   119
        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
   120
            continue
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   121
        for name in names:
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   122
            ui.write(".. _%s:\n" % name)
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   123
        ui.write("\n")
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   124
        if sectionfunc:
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   125
            ui.write(sectionfunc(sec))
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   126
        if util.safehasattr(doc, '__call__'):
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   127
            doc = doc()
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   128
        ui.write(doc)
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   129
        ui.write("\n")
81d9a7f6f2e7 gendoc: extract print help topics into a dedicated function
Takumi IINO <trot.thunder@gmail.com>
parents: 19231
diff changeset
   130
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
   131
def commandprinter(ui, cmdtable, sectionfunc):
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   132
    h = {}
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
   133
    for c, attr in cmdtable.items():
6488
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   134
        f = c.split("|")[0]
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   135
        f = f.lstrip("^")
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   136
        h[f] = c
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   137
    cmds = h.keys()
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   138
    cmds.sort()
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   139
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   140
    for f in cmds:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 9792
diff changeset
   141
        if f.startswith("debug"):
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 9792
diff changeset
   142
            continue
12756
13f0acfa974a gendoc: refactor get_cmd
Erik Zielke <ez@aragost.com>
parents: 11570
diff changeset
   143
        d = get_cmd(h[f], cmdtable)
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17267
diff changeset
   144
        ui.write(sectionfunc(d['cmd']))
6488
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   145
        # synopsis
12813
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   146
        ui.write("::\n\n")
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   147
        synopsislines = d['synopsis'].splitlines()
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   148
        for line in synopsislines:
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   149
            # some commands (such as rebase) have a multi-line
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   150
            # synopsis
12814
58bc5024805d gendoc: do not strip 'hg ' from synopsis
Martin Geisler <mg@lazybytes.net>
parents: 12813
diff changeset
   151
            ui.write("   %s\n" % line)
12813
13fdef670c43 gendoc: support multi-line synopses
Martin Geisler <mg@lazybytes.net>
parents: 12812
diff changeset
   152
        ui.write('\n')
6488
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   153
        # description
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   154
        ui.write("%s\n\n" % d['desc'][1])
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   155
        # options
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   156
        opt_output = list(d['opts'])
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   157
        if opt_output:
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   158
            opts_len = max([len(line[0]) for line in opt_output])
13345
b8214d871338 doc: Capitalize the "options" header of mercurial commands
Javi Merino <cibervicho@gmail.com>
parents: 13077
diff changeset
   159
            ui.write(_("Options:\n\n"))
6488
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   160
            for optstr, desc in opt_output:
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   161
                if desc:
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   162
                    s = "%-*s  %s" % (opts_len, optstr, desc)
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   163
                else:
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   164
                    s = optstr
12780
bdc1cf692447 gendoc: dedent documentation from docstrings
Erik Zielke <ez@aragost.com>
parents: 12777
diff changeset
   165
                ui.write("%s\n" % s)
6488
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   166
            ui.write("\n")
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   167
        # aliases
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   168
        if d['aliases']:
119dff2cd592 gendoc: fix indentation
Christian Ebert <blacktrash@gmx.net>
parents: 5209
diff changeset
   169
            ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   170
3797
54fd4d3b4fce Generate docs for help topics
Matt Mackall <mpm@selenic.com>
parents: 1814
diff changeset
   171
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
   172
def allextensionnames():
14316
d5b525697ddb extensions: drop maxlength from enabled and disabled
Matt Mackall <mpm@selenic.com>
parents: 13345
diff changeset
   173
    return extensions.enabled().keys() + extensions.disabled().keys()
12781
0d09991f91ee gendoc: automatically create help for default extensions.
Erik Zielke <ez@aragost.com>
parents: 12780
diff changeset
   174
1814
7956893e8458 generate hg manpage from commands.py docstring
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   175
if __name__ == "__main__":
19425
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   176
    doc = 'hg.1.gendoc'
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   177
    if len(sys.argv) > 1:
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   178
        doc = sys.argv[1]
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   179
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   180
    if doc == 'hg.1.gendoc':
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   181
        showdoc(sys.stdout)
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   182
    else:
81fbd4e66ff5 gendoc: dispatch print document content by commandline arguments
Takumi IINO <trot.thunder@gmail.com>
parents: 19424
diff changeset
   183
        showtopic(sys.stdout, sys.argv[1])