annotate mercurial/help.py @ 32164:29e286fa4db0

changegroup: deduplicate 'getlocalchangegroup' The two functions 'getlocalchangegroup' and 'getchangegroup' have been strictly identical for multiple years ('getchangegroup' had a deprecated docstring) We'll drop one of them (getlocalchangegroup, since it has the longest name). However, we needs to migrate all users of the dropped one to the new one before we can deprecate it. In the mean time we drop one of the duplicated definition and the outdated docstring.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 04 May 2017 12:36:45 +0200
parents 964c6be36590
children bd872f64a8ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3795
17a11f4ff260 Add basic support for help topics and a dates topic
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
1 # help.py - help data for mercurial
17a11f4ff260 Add basic support for help topics and a dates topic
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2 #
17a11f4ff260 Add basic support for help topics and a dates topic
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
17a11f4ff260 Add basic support for help topics and a dates topic
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8159
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9785
diff changeset
6 # GNU General Public License version 2 or any later version.
3795
17a11f4ff260 Add basic support for help topics and a dates topic
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7
27479
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
8 from __future__ import absolute_import
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
9
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
10 import itertools
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
11 import os
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
12 import textwrap
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
13
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
14 from .i18n import (
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
15 _,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
16 gettext,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
17 )
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
18 from . import (
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
19 cmdutil,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
20 encoding,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
21 error,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
22 extensions,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
23 filemerge,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
24 fileset,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
25 minirst,
32143
964c6be36590 py3: make sure opts are passed and used correctly in help command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32076
diff changeset
26 pycompat,
27479
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
27 revset,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
28 templatefilters,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
29 templatekw,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
30 templater,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
31 util,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
32 )
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
33 from .hgweb import (
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
34 webcommands,
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
35 )
8863
7b19c3c0172b help: adding a new help topic about extensions
Cédric Duval <cedricduval@free.fr>
parents: 8668
diff changeset
36
31080
6918c9215201 help: hide command line options marked as "advanced"
Jun Wu <quark@fb.com>
parents: 31061
diff changeset
37 _exclkeywords = set([
6918c9215201 help: hide command line options marked as "advanced"
Jun Wu <quark@fb.com>
parents: 31061
diff changeset
38 "(ADVANCED)",
26370
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
39 "(DEPRECATED)",
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
40 "(EXPERIMENTAL)",
31080
6918c9215201 help: hide command line options marked as "advanced"
Jun Wu <quark@fb.com>
parents: 31061
diff changeset
41 # i18n: "(ADVANCED)" is a keyword, must be translated consistently
6918c9215201 help: hide command line options marked as "advanced"
Jun Wu <quark@fb.com>
parents: 31061
diff changeset
42 _("(ADVANCED)"),
26370
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
43 # i18n: "(DEPRECATED)" is a keyword, must be translated consistently
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
44 _("(DEPRECATED)"),
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
45 # i18n: "(EXPERIMENTAL)" is a keyword, must be translated consistently
44cc9f63a2f1 help: include parens in DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26369
diff changeset
46 _("(EXPERIMENTAL)"),
31080
6918c9215201 help: hide command line options marked as "advanced"
Jun Wu <quark@fb.com>
parents: 31061
diff changeset
47 ])
26369
4799b5c4aaf4 help: define list of keywords that should be excluded from non-verbose output
Yuya Nishihara <yuya@tcha.org>
parents: 26238
diff changeset
48
20582
02c303f64917 help: exclude deprecated extensions in the disabled part of 'help extensions'
Augie Fackler <raf@durin42.com>
parents: 20034
diff changeset
49 def listexts(header, exts, indent=1, showdeprecated=False):
8879
d0a3eadfbdb3 help: more improvements for the extensions topic
Cédric Duval <cedricduval@free.fr>
parents: 8871
diff changeset
50 '''return a text listing of the given extensions'''
16852
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
51 rst = []
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
52 if exts:
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
53 for name, desc in sorted(exts.iteritems()):
26371
51b309ce6c7d help: unify handling of DEPRECATED/EXPERIMENTAL keywords
Yuya Nishihara <yuya@tcha.org>
parents: 26370
diff changeset
54 if not showdeprecated and any(w in desc for w in _exclkeywords):
20582
02c303f64917 help: exclude deprecated extensions in the disabled part of 'help extensions'
Augie Fackler <raf@durin42.com>
parents: 20034
diff changeset
55 continue
16852
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
56 rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
27151
7625f6387fc4 help: make listexts less confusing for deprecated exts
timeless <timeless@mozdev.org>
parents: 26845
diff changeset
57 if rst:
7625f6387fc4 help: make listexts less confusing for deprecated exts
timeless <timeless@mozdev.org>
parents: 26845
diff changeset
58 rst.insert(0, '\n%s\n\n' % header)
16852
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
59 return rst
8864
cad6370a15cb help: refactor extensions listing, and show enabled ones in the dedicated topic
Cédric Duval <cedricduval@free.fr>
parents: 8863
diff changeset
60
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
61 def extshelp(ui):
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
62 rst = loaddoc('extensions')(ui).splitlines(True)
20582
02c303f64917 help: exclude deprecated extensions in the disabled part of 'help extensions'
Augie Fackler <raf@durin42.com>
parents: 20034
diff changeset
63 rst.extend(listexts(
02c303f64917 help: exclude deprecated extensions in the disabled part of 'help extensions'
Augie Fackler <raf@durin42.com>
parents: 20034
diff changeset
64 _('enabled extensions:'), extensions.enabled(), showdeprecated=True))
16852
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
65 rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
af69b2b64d6e help: format extension lists using RST
Olav Reinert <seroton10@gmail.com>
parents: 16845
diff changeset
66 doc = ''.join(rst)
8863
7b19c3c0172b help: adding a new help topic about extensions
Cédric Duval <cedricduval@free.fr>
parents: 8668
diff changeset
67 return doc
7013
f56e788fa292 i18n: mark help strings for translation
Martin Geisler <mg@daimi.au.dk>
parents: 7012
diff changeset
68
22116
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
69 def optrst(header, options, verbose):
16781
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
70 data = []
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
71 multioccur = False
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
72 for option in options:
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
73 if len(option) == 5:
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
74 shortopt, longopt, default, desc, optlabel = option
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
75 else:
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
76 shortopt, longopt, default, desc = option
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
77 optlabel = _("VALUE") # default label
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
78
26369
4799b5c4aaf4 help: define list of keywords that should be excluded from non-verbose output
Yuya Nishihara <yuya@tcha.org>
parents: 26238
diff changeset
79 if not verbose and any(w in desc for w in _exclkeywords):
16781
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
80 continue
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
81
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
82 so = ''
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
83 if shortopt:
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
84 so = '-' + shortopt
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
85 lo = '--' + longopt
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
86 if default:
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
87 desc += _(" (default: %s)") % default
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
88
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
89 if isinstance(default, list):
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
90 lo += " %s [+]" % optlabel
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
91 multioccur = True
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
92 elif (default is not None) and not isinstance(default, bool):
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
93 lo += " %s" % optlabel
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
94
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
95 data.append((so, lo, desc))
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
96
22117
c1d93edcf004 help: fold repeatable option message into option table header
Matt Mackall <mpm@selenic.com>
parents: 22116
diff changeset
97 if multioccur:
c1d93edcf004 help: fold repeatable option message into option table header
Matt Mackall <mpm@selenic.com>
parents: 22116
diff changeset
98 header += (_(" ([+] can be repeated)"))
16781
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
99
22116
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
100 rst = ['\n%s:\n\n' % header]
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
101 rst.extend(minirst.maketable(data, 1))
16781
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
102
16815
e740746ea557 minirst: generate tables as a list of joined lines
Olav Reinert <seroton10@gmail.com>
parents: 16781
diff changeset
103 return ''.join(rst)
16781
c0b98f436cce help: move some helper functions to help.py
Olav Reinert <seroton10@gmail.com>
parents: 16711
diff changeset
104
17837
b623e323c561 help: indicate help omitting if help document is not fully displayed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17323
diff changeset
105 def indicateomitted(rst, omitted, notomitted=None):
b623e323c561 help: indicate help omitting if help document is not fully displayed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17323
diff changeset
106 rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted)
b623e323c561 help: indicate help omitting if help document is not fully displayed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17323
diff changeset
107 if notomitted:
b623e323c561 help: indicate help omitting if help document is not fully displayed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17323
diff changeset
108 rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted)
b623e323c561 help: indicate help omitting if help document is not fully displayed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17323
diff changeset
109
27323
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
110 def filtercmd(ui, cmd, kw, doc):
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
111 if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
112 return True
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
113 if not ui.verbose and doc and any(w in doc for w in _exclkeywords):
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
114 return True
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
115 return False
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
116
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
117 def topicmatch(ui, kw):
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
118 """Return help topics matching kw.
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
119
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
120 Returns {'section': [(name, summary), ...], ...} where section is
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
121 one of topics, commands, extensions, or extensioncommands.
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
122 """
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
123 kw = encoding.lower(kw)
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
124 def lowercontains(container):
16845
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
125 return kw in encoding.lower(container) # translated in helptable
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
126 results = {'topics': [],
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
127 'commands': [],
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
128 'extensions': [],
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
129 'extensioncommands': [],
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
130 }
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
131 for names, header, doc in helptable:
22322
e284de138f00 help: only call doc() when it is callable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21796
diff changeset
132 # Old extensions may use a str as doc.
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
133 if (sum(map(lowercontains, names))
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
134 or lowercontains(header)
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
135 or (callable(doc) and lowercontains(doc(ui)))):
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
136 results['topics'].append((names[0], header))
27479
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
137 from . import commands # avoid cycle
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
138 for cmd, entry in commands.table.iteritems():
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
139 if len(entry) == 3:
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
140 summary = entry[2]
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
141 else:
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
142 summary = ''
16845
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
143 # translate docs *before* searching there
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
144 docs = _(getattr(entry[0], '__doc__', None)) or ''
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
145 if kw in cmd or lowercontains(summary) or lowercontains(docs):
16845
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
146 doclines = docs.splitlines()
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
147 if doclines:
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
148 summary = doclines[0]
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
149 cmdname = cmd.partition('|')[0].lstrip('^')
27324
5456374561a7 help: call filtercmd from topicmatch
timeless <timeless@mozdev.org>
parents: 27323
diff changeset
150 if filtercmd(ui, cmdname, kw, docs):
5456374561a7 help: call filtercmd from topicmatch
timeless <timeless@mozdev.org>
parents: 27323
diff changeset
151 continue
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
152 results['commands'].append((cmdname, summary))
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
153 for name, docs in itertools.chain(
19769
83d79a00cc24 help: use full name of extensions to look up them for keyword search
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 18748
diff changeset
154 extensions.enabled(False).iteritems(),
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
155 extensions.disabled().iteritems()):
28058
ff6e8dc659f8 help: don't crash in keyword search if an extension fails to provide docs
Simon Farnsworth <simonfar@fb.com>
parents: 27660
diff changeset
156 if not docs:
ff6e8dc659f8 help: don't crash in keyword search if an extension fails to provide docs
Simon Farnsworth <simonfar@fb.com>
parents: 27660
diff changeset
157 continue
27660
512f883c234c mercurial: pass ui to extensions.load (issue5007)
Jun Wu <quark@fb.com>
parents: 27631
diff changeset
158 mod = extensions.load(ui, name, '')
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
159 name = name.rpartition('.')[-1]
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
160 if lowercontains(name) or lowercontains(docs):
16845
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
161 # extension docs are already translated
4594729c61ee help: fix search with `-k` option in non-ASCII locales
Nikolaj Sjujskij <sterkrig@myopera.com>
parents: 16816
diff changeset
162 results['extensions'].append((name, docs.splitlines()[0]))
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
163 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
16711
497deec204d1 help: add --keyword (-k) for searching help
Augie Fackler <raf@durin42.com>
parents: 16710
diff changeset
164 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
165 cmdname = cmd.partition('|')[0].lstrip('^')
16942
87882c8753d4 help: fix extension commands help in keyword search
Olav Reinert <seroton10@gmail.com>
parents: 16884
diff changeset
166 if entry[0].__doc__:
87882c8753d4 help: fix extension commands help in keyword search
Olav Reinert <seroton10@gmail.com>
parents: 16884
diff changeset
167 cmddoc = gettext(entry[0].__doc__).splitlines()[0]
16884
4fd1f1d7569b help: fix 'hg help -k' matching an extension without docs
Thomas Arendsen Hein <thomas@intevation.de>
parents: 16855
diff changeset
168 else:
4fd1f1d7569b help: fix 'hg help -k' matching an extension without docs
Thomas Arendsen Hein <thomas@intevation.de>
parents: 16855
diff changeset
169 cmddoc = _('(no help text available)')
27387
dfab0afde928 help: filter extension commands
timeless <timeless@mozdev.org>
parents: 27379
diff changeset
170 if filtercmd(ui, cmdname, kw, cmddoc):
dfab0afde928 help: filter extension commands
timeless <timeless@mozdev.org>
parents: 27379
diff changeset
171 continue
16884
4fd1f1d7569b help: fix 'hg help -k' matching an extension without docs
Thomas Arendsen Hein <thomas@intevation.de>
parents: 16855
diff changeset
172 results['extensioncommands'].append((cmdname, cmddoc))
16710
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
173 return results
a17983680f12 help: introduce topicmatch for finding topics matching a keyword
Augie Fackler <raf@durin42.com>
parents: 16568
diff changeset
174
27375
c4a062d090ee help: teach loaddoc to load from a different directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27325
diff changeset
175 def loaddoc(topic, subdir=None):
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
176 """Return a delayed loader for help/topic.txt."""
3798
6f0c42d50394 move environment topic
Matt Mackall <mpm@selenic.com>
parents: 3795
diff changeset
177
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
178 def loader(ui):
22637
149141c3a25f help: don't search randomly for help data - trust util.datapath
Mads Kiilerich <madski@unity3d.com>
parents: 22633
diff changeset
179 docdir = os.path.join(util.datapath, 'help')
27375
c4a062d090ee help: teach loaddoc to load from a different directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27325
diff changeset
180 if subdir:
c4a062d090ee help: teach loaddoc to load from a different directory
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27325
diff changeset
181 docdir = os.path.join(docdir, subdir)
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
182 path = os.path.join(docdir, topic + ".txt")
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14044
diff changeset
183 doc = gettext(util.readfile(path))
12820
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
184 for rewriter in helphooks.get(topic, []):
26414
c44b507e7c78 help: pass around ui to rewriter hooks (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26413
diff changeset
185 doc = rewriter(ui, topic, doc)
12820
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
186 return doc
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
187
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
188 return loader
7677
6a0bc2dc9da6 help: add a topic about some of the templating features
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7387
diff changeset
189
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
190 internalstable = sorted([
29747
aba2bb2a6d0f help: don't try to render a section on sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28828
diff changeset
191 (['bundles'], _('Bundles'),
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
192 loaddoc('bundles', subdir='internals')),
31293
2cdb1239ff8c help: update help.internalstable for new censor docs
Augie Fackler <augie@google.com>
parents: 31265
diff changeset
193 (['censor'], _('Censor'),
2cdb1239ff8c help: update help.internalstable for new censor docs
Augie Fackler <augie@google.com>
parents: 31265
diff changeset
194 loaddoc('censor', subdir='internals')),
29747
aba2bb2a6d0f help: don't try to render a section on sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28828
diff changeset
195 (['changegroups'], _('Changegroups'),
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
196 loaddoc('changegroups', subdir='internals')),
29747
aba2bb2a6d0f help: don't try to render a section on sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28828
diff changeset
197 (['requirements'], _('Repository Requirements'),
28523
045fe7042510 help: document requirements
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28058
diff changeset
198 loaddoc('requirements', subdir='internals')),
29747
aba2bb2a6d0f help: don't try to render a section on sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28828
diff changeset
199 (['revlogs'], _('Revision Logs'),
27631
c18292a6ff54 internals: document revlog format
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27479
diff changeset
200 loaddoc('revlogs', subdir='internals')),
29859
a1092e2d70a3 help: internals topic for wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29747
diff changeset
201 (['wireprotocol'], _('Wire Protocol'),
a1092e2d70a3 help: internals topic for wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29747
diff changeset
202 loaddoc('wireprotocol', subdir='internals')),
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
203 ])
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
204
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
205 def internalshelp(ui):
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
206 """Generate the index for the "internals" topic."""
32076
d7b698ae153b help: explain how to access subtopics in internals
Matt DeVore <matvore@google.com>
parents: 31793
diff changeset
207 lines = ['To access a subtopic, use "hg help internals.{subtopic-name}"\n',
d7b698ae153b help: explain how to access subtopics in internals
Matt DeVore <matvore@google.com>
parents: 31793
diff changeset
208 '\n']
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
209 for names, header, doc in internalstable:
27400
64208bd4c580 help: add missed last new line to "internals" topic
Yuya Nishihara <yuya@tcha.org>
parents: 27387
diff changeset
210 lines.append(' :%s: %s\n' % (names[0], header))
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
211
27400
64208bd4c580 help: add missed last new line to "internals" topic
Yuya Nishihara <yuya@tcha.org>
parents: 27387
diff changeset
212 return ''.join(lines)
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
213
13888
9e5407a67dea help: sort help topics to make the output more readable (issue2751)
Yun Lee <yunlee.bj@gmail.com>
parents: 13593
diff changeset
214 helptable = sorted([
31793
69d8fcf20014 help: document bundle specifications
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31293
diff changeset
215 (['bundlespec'], _("Bundle File Formats"), loaddoc('bundlespec')),
31129
71f692f1f678 color: update the help table
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31080
diff changeset
216 (['color'], _("Colorizing Outputs"), loaddoc('color')),
12145
c407b4ca666e help: make "hg help hgrc" an alias for "hg help config"
Martin Geisler <mg@lazybytes.net>
parents: 11657
diff changeset
217 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
218 (["dates"], _("Date Formats"), loaddoc('dates')),
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
219 (["patterns"], _("File Name Patterns"), loaddoc('patterns')),
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
220 (['environment', 'env'], _('Environment Variables'),
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
221 loaddoc('environment')),
30769
e520f0f4b1cf help: merge revsets.txt into revisions.txt
Martin von Zweigbergk <martinvonz@google.com>
parents: 30610
diff changeset
222 (['revisions', 'revs', 'revsets', 'revset', 'multirevs', 'mrevs'],
e520f0f4b1cf help: merge revsets.txt into revisions.txt
Martin von Zweigbergk <martinvonz@google.com>
parents: 30610
diff changeset
223 _('Specifying Revisions'), loaddoc('revisions')),
17322
7124f984dc8d help: use the first topic name from helptable, not the longest alias
Mads Kiilerich <mads@kiilerich.com>
parents: 17321
diff changeset
224 (['filesets', 'fileset'], _("Specifying File Sets"), loaddoc('filesets')),
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
225 (['diffs'], _('Diff Formats'), loaddoc('diffs')),
30812
98bfce9bd5e5 help: make "mergetool" an alias for "merge-tools"
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30769
diff changeset
226 (['merge-tools', 'mergetools', 'mergetool'], _('Merge Tools'),
98bfce9bd5e5 help: make "mergetool" an alias for "merge-tools"
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30769
diff changeset
227 loaddoc('merge-tools')),
16568
770190bff625 help: add reference to template help (issue3413)
A. S. Budden <abudden@gmail.com>
parents: 16547
diff changeset
228 (['templating', 'templates', 'template', 'style'], _('Template Usage'),
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
229 loaddoc('templates')),
9539
c904e76e3834 help: move help topics from mercurial/help.py to help/*.txt
Martin Geisler <mg@lazybytes.net>
parents: 9536
diff changeset
230 (['urls'], _('URL Paths'), loaddoc('urls')),
16547
23072be2eaa3 help: consistently use title capitalization for help topics
Martin Geisler <mg@aragost.com>
parents: 16250
diff changeset
231 (["extensions"], _("Using Additional Features"), extshelp),
17322
7124f984dc8d help: use the first topic name from helptable, not the longest alias
Mads Kiilerich <mads@kiilerich.com>
parents: 17321
diff changeset
232 (["subrepos", "subrepo"], _("Subrepositories"), loaddoc('subrepos')),
17321
f3fd9d6802b7 help: fix helptable indentation
Mads Kiilerich <mads@kiilerich.com>
parents: 17187
diff changeset
233 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
f3fd9d6802b7 help: fix helptable indentation
Mads Kiilerich <mads@kiilerich.com>
parents: 17187
diff changeset
234 (["glossary"], _("Glossary"), loaddoc('glossary')),
f3fd9d6802b7 help: fix helptable indentation
Mads Kiilerich <mads@kiilerich.com>
parents: 17187
diff changeset
235 (["hgignore", "ignore"], _("Syntax for Mercurial Ignore Files"),
f3fd9d6802b7 help: fix helptable indentation
Mads Kiilerich <mads@kiilerich.com>
parents: 17187
diff changeset
236 loaddoc('hgignore')),
f3fd9d6802b7 help: fix helptable indentation
Mads Kiilerich <mads@kiilerich.com>
parents: 17187
diff changeset
237 (["phases"], _("Working with Phases"), loaddoc('phases')),
25881
9de443515f1d help: scripting help topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
238 (['scripting'], _('Using Mercurial from scripts and automation'),
9de443515f1d help: scripting help topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
239 loaddoc('scripting')),
27376
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
240 (['internals'], _("Technical implementation topics"),
fc810d950278 help: add "internals" topic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27375
diff changeset
241 internalshelp),
31061
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31059
diff changeset
242 (['pager'], _("Pager Support"), loaddoc('pager')),
13888
9e5407a67dea help: sort help topics to make the output more readable (issue2751)
Yun Lee <yunlee.bj@gmail.com>
parents: 13593
diff changeset
243 ])
12820
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
244
27379
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
245 # Maps topics with sub-topics to a list of their sub-topics.
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
246 subtopics = {
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
247 'internals': internalstable,
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
248 }
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
249
12820
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
250 # Map topics to lists of callable taking the current topic help and
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
251 # returning the updated version
14318
1f46be4689ed help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents: 14317
diff changeset
252 helphooks = {}
12820
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
253
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
254 def addtopichook(topic, rewriter):
0edc0aa7432d help: add topic rewriting hooks
Patrick Mezard <pmezard@gmail.com>
parents: 12818
diff changeset
255 helphooks.setdefault(topic, []).append(rewriter)
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
256
26414
c44b507e7c78 help: pass around ui to rewriter hooks (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26413
diff changeset
257 def makeitemsdoc(ui, topic, doc, marker, items, dedent=False):
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
258 """Extract docstring from the items key to function mapping, build a
26196
3a4620ad4490 help: fix makeitemsdoc English description
timeless@mozdev.org
parents: 25881
diff changeset
259 single documentation block and use it to overwrite the marker in doc.
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
260 """
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
261 entries = []
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
262 for name in sorted(items):
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
263 text = (items[name].__doc__ or '').rstrip()
26415
46af0adb5c37 help: hide deprecated filesets, revsets and template items if not verbose
Yuya Nishihara <yuya@tcha.org>
parents: 26414
diff changeset
264 if (not text
46af0adb5c37 help: hide deprecated filesets, revsets and template items if not verbose
Yuya Nishihara <yuya@tcha.org>
parents: 26414
diff changeset
265 or not ui.verbose and any(w in text for w in _exclkeywords)):
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
266 continue
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
267 text = gettext(text)
24098
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
268 if dedent:
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
269 text = textwrap.dedent(text)
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
270 lines = text.splitlines()
16250
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
271 doclines = [(lines[0])]
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
272 for l in lines[1:]:
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
273 # Stop once we find some Python doctest
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
274 if l.strip().startswith('>>>'):
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
275 break
24098
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
276 if dedent:
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
277 doclines.append(l.rstrip())
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
278 else:
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
279 doclines.append(' ' + l.strip())
16250
684864d54903 help: strip doctest from dochelp
"Yann E. MORIN" <yann.morin.1998@free.fr>
parents: 16126
diff changeset
280 entries.append('\n'.join(doclines))
13593
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
281 entries = '\n\n'.join(entries)
cc4721ed7a2a help: extract items doc generation function
Patrick Mezard <pmezard@gmail.com>
parents: 12828
diff changeset
282 return doc.replace(marker, entries)
14318
1f46be4689ed help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents: 14317
diff changeset
283
24098
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
284 def addtopicsymbols(topic, marker, symbols, dedent=False):
26414
c44b507e7c78 help: pass around ui to rewriter hooks (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26413
diff changeset
285 def add(ui, topic, doc):
c44b507e7c78 help: pass around ui to rewriter hooks (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26413
diff changeset
286 return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent)
14318
1f46be4689ed help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents: 14317
diff changeset
287 addtopichook(topic, add)
1f46be4689ed help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents: 14317
diff changeset
288
31793
69d8fcf20014 help: document bundle specifications
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31293
diff changeset
289 addtopicsymbols('bundlespec', '.. bundlecompressionmarker',
69d8fcf20014 help: document bundle specifications
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31293
diff changeset
290 util.bundlecompressiontopics())
14686
6ab8b17adc03 fileset: add a help topic
Matt Mackall <mpm@selenic.com>
parents: 14318
diff changeset
291 addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols)
24099
be83fd9d46d5 help.merge-tools: do not double document merge tools
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24098
diff changeset
292 addtopicsymbols('merge-tools', '.. internaltoolsmarker',
be83fd9d46d5 help.merge-tools: do not double document merge tools
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24098
diff changeset
293 filemerge.internalsdoc)
30769
e520f0f4b1cf help: merge revsets.txt into revisions.txt
Martin von Zweigbergk <martinvonz@google.com>
parents: 30610
diff changeset
294 addtopicsymbols('revisions', '.. predicatesmarker', revset.symbols)
26436
a2291c9c85a1 templatekw: remove dockeywords hack
Yuya Nishihara <yuya@tcha.org>
parents: 26415
diff changeset
295 addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords)
14318
1f46be4689ed help: consolidate topic hooks in help.py
Matt Mackall <mpm@selenic.com>
parents: 14317
diff changeset
296 addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)
24587
76c0b4cfa039 help: populate template functions via docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24099
diff changeset
297 addtopicsymbols('templates', '.. functionsmarker', templater.funcs)
24098
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
298 addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands,
067540702f64 help: teach topic symbols how to dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24080
diff changeset
299 dedent=True)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
300
27377
d1c998d7b103 help: pass subtopic into help()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27376
diff changeset
301 def help_(ui, name, unknowncmd=False, full=True, subtopic=None, **opts):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
302 '''
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
303 Generate the help for 'name' as unformatted restructured text. If
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
304 'name' is None, describe the commands available.
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
305 '''
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
306
27479
3ce1d50daa99 help: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27400
diff changeset
307 from . import commands # avoid cycle
32143
964c6be36590 py3: make sure opts are passed and used correctly in help command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32076
diff changeset
308 opts = pycompat.byteskwargs(opts)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
309
27378
c709b515218e help: pass sub-topic into help query functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27377
diff changeset
310 def helpcmd(name, subtopic=None):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
311 try:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
312 aliases, entry = cmdutil.findcmd(name, commands.table,
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
313 strict=unknowncmd)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24871
diff changeset
314 except error.AmbiguousCommand as inst:
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
315 # py3k fix: except vars can't be used outside the scope of the
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
316 # except block, nor can be used inside a lambda. python issue4617
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
317 prefix = inst.args[0]
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
318 select = lambda c: c.lstrip('^').startswith(prefix)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
319 rst = helplist(select)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
320 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
321
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
322 rst = []
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
323
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
324 # check if it's an invalid alias and display its error if it is
22160
645457f73aa6 alias: keep error message in "badalias" so that help can see it
Yuya Nishihara <yuya@tcha.org>
parents: 22118
diff changeset
325 if getattr(entry[0], 'badalias', None):
22162
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
326 rst.append(entry[0].badalias + '\n')
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
327 if entry[0].unknowncmd:
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
328 try:
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
329 rst.extend(helpextcmd(entry[0].cmdname))
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
330 except error.UnknownCommand:
7ada34676db8 help: provide help of bad alias without executing aliascmd()
Yuya Nishihara <yuya@tcha.org>
parents: 22160
diff changeset
331 pass
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
332 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
333
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
334 # synopsis
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
335 if len(entry) > 2:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
336 if entry[2].startswith('hg'):
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
337 rst.append("%s\n" % entry[2])
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
338 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
339 rst.append('hg %s %s\n' % (aliases[0], entry[2]))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
340 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
341 rst.append('hg %s\n' % aliases[0])
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
342 # aliases
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
343 if full and not ui.quiet and len(aliases) > 1:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
344 rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:]))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
345 rst.append('\n')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
346
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
347 # description
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
348 doc = gettext(entry[0].__doc__)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
349 if not doc:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
350 doc = _("(no help text available)")
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
351 if util.safehasattr(entry[0], 'definition'): # aliased command
28828
3640c1702c43 help: report source of aliases
timeless <timeless@mozdev.org>
parents: 28523
diff changeset
352 source = entry[0].source
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
353 if entry[0].definition.startswith('!'): # shell alias
28828
3640c1702c43 help: report source of aliases
timeless <timeless@mozdev.org>
parents: 28523
diff changeset
354 doc = (_('shell alias for::\n\n %s\n\ndefined by: %s\n') %
3640c1702c43 help: report source of aliases
timeless <timeless@mozdev.org>
parents: 28523
diff changeset
355 (entry[0].definition[1:], source))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
356 else:
28828
3640c1702c43 help: report source of aliases
timeless <timeless@mozdev.org>
parents: 28523
diff changeset
357 doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') %
3640c1702c43 help: report source of aliases
timeless <timeless@mozdev.org>
parents: 28523
diff changeset
358 (entry[0].definition, doc, source))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
359 doc = doc.splitlines(True)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
360 if ui.quiet or not full:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
361 rst.append(doc[0])
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
362 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
363 rst.extend(doc)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
364 rst.append('\n')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
365
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
366 # check if this command shadows a non-trivial (multi-line)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
367 # extension help text
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
368 try:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
369 mod = extensions.find(name)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
370 doc = gettext(mod.__doc__) or ''
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
371 if '\n' in doc.strip():
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
372 msg = _("(use 'hg help -e %s' to show help for "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
373 "the %s extension)") % (name, name)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
374 rst.append('\n%s\n' % msg)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
375 except KeyError:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
376 pass
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
377
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
378 # options
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
379 if not ui.quiet and entry[1]:
22116
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
380 rst.append(optrst(_("options"), entry[1], ui.verbose))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
381
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
382 if ui.verbose:
22116
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
383 rst.append(optrst(_("global options"),
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
384 commands.globalopts, ui.verbose))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
385
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
386 if not ui.verbose:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
387 if not full:
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
388 rst.append(_("\n(use 'hg %s -h' to show more help)\n")
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
389 % name)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
390 elif not ui.quiet:
22110
26f7c8033bed help: tweak --verbose command help hint
Matt Mackall <mpm@selenic.com>
parents: 21796
diff changeset
391 rst.append(_('\n(some details hidden, use --verbose '
26f7c8033bed help: tweak --verbose command help hint
Matt Mackall <mpm@selenic.com>
parents: 21796
diff changeset
392 'to show complete help)'))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
393
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
394 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
395
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
396
27325
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
397 def helplist(select=None, **opts):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
398 # list of commands
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
399 if name == "shortlist":
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
400 header = _('basic commands:\n\n')
20822
be87397f98c9 help: let 'hg help debug' show the list of secret debug commands
Mads Kiilerich <madski@unity3d.com>
parents: 20743
diff changeset
401 elif name == "debug":
be87397f98c9 help: let 'hg help debug' show the list of secret debug commands
Mads Kiilerich <madski@unity3d.com>
parents: 20743
diff changeset
402 header = _('debug commands (internal and unsupported):\n\n')
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
403 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
404 header = _('list of commands:\n\n')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
405
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
406 h = {}
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
407 cmds = {}
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
408 for c, e in commands.table.iteritems():
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
409 f = c.partition("|")[0]
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
410 if select and not select(f):
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
411 continue
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
412 if (not select and name != 'shortlist' and
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
413 e[0].__module__ != commands.__name__):
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
414 continue
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
415 if name == "shortlist" and not f.startswith("^"):
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
416 continue
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
417 f = f.lstrip("^")
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
418 doc = e[0].__doc__
27323
0fe93498ef07 help: refactor filtercmd
timeless <timeless@mozdev.org>
parents: 27152
diff changeset
419 if filtercmd(ui, f, name, doc):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
420 continue
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
421 doc = gettext(doc)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
422 if not doc:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
423 doc = _("(no help text available)")
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
424 h[f] = doc.splitlines()[0].rstrip()
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
425 cmds[f] = c.lstrip("^")
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
426
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
427 rst = []
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
428 if not h:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
429 if not ui.quiet:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
430 rst.append(_('no commands defined\n'))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
431 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
432
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
433 if not ui.quiet:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
434 rst.append(header)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
435 fns = sorted(h)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
436 for f in fns:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
437 if ui.verbose:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
438 commacmds = cmds[f].replace("|",", ")
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
439 rst.append(" :%s: %s\n" % (commacmds, h[f]))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
440 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
441 rst.append(' :%s: %s\n' % (f, h[f]))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
442
27325
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
443 ex = opts.get
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
444 anyopts = (ex('keyword') or not (ex('command') or ex('extension')))
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
445 if not name and anyopts:
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
446 exts = listexts(_('enabled extensions:'), extensions.enabled())
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
447 if exts:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
448 rst.append('\n')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
449 rst.extend(exts)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
450
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
451 rst.append(_("\nadditional help topics:\n\n"))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
452 topics = []
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
453 for names, header, doc in helptable:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
454 topics.append((names[0], header))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
455 for t, desc in topics:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
456 rst.append(" :%s: %s\n" % (t, desc))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
457
22115
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
458 if ui.quiet:
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
459 pass
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
460 elif ui.verbose:
22116
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
461 rst.append('\n%s\n' % optrst(_("global options"),
161085f87b95 help: roll option list header into option formatter
Matt Mackall <mpm@selenic.com>
parents: 22115
diff changeset
462 commands.globalopts, ui.verbose))
22115
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
463 if name == 'shortlist':
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
464 rst.append(_("\n(use 'hg help' for the full list "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
465 "of commands)\n"))
22115
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
466 else:
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
467 if name == 'shortlist':
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
468 rst.append(_("\n(use 'hg help' for the full list of commands "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
469 "or 'hg -v' for details)\n"))
22115
8465625f7364 help: refactor helplist optlist mess
Matt Mackall <mpm@selenic.com>
parents: 22114
diff changeset
470 elif name and not full:
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
471 rst.append(_("\n(use 'hg help %s' to show the full help "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
472 "text)\n") % name)
23624
861ddedfb402 help: suggest '-v -e' to get built-in aliases for extensions (issue4461)
Chingis Dugarzhapov <chingis.dug@gmail.com>
parents: 22637
diff changeset
473 elif name and cmds and name in cmds.keys():
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
474 rst.append(_("\n(use 'hg help -v -e %s' to show built-in "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
475 "aliases and global options)\n") % name)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
476 else:
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
477 rst.append(_("\n(use 'hg help -v%s' to show built-in aliases "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
478 "and global options)\n")
22118
9a299c39de01 help: normalize helplist hints
Matt Mackall <mpm@selenic.com>
parents: 22117
diff changeset
479 % (name and " " + name or ""))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
480 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
481
27378
c709b515218e help: pass sub-topic into help query functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27377
diff changeset
482 def helptopic(name, subtopic=None):
27379
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
483 # Look for sub-topic entry first.
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
484 header, doc = None, None
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
485 if subtopic and name in subtopics:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
486 for names, header, doc in subtopics[name]:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
487 if subtopic in names:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
488 break
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
489
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
490 if not header:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
491 for names, header, doc in helptable:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
492 if name in names:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
493 break
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
494 else:
2278870bb997 help: support loading sub-topics
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27378
diff changeset
495 raise error.UnknownCommand(name)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
496
18748
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 18746
diff changeset
497 rst = [minirst.section(header)]
6e676fb6ea44 help: use a full header for topic titles
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 18746
diff changeset
498
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
499 # description
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
500 if not doc:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
501 rst.append(" %s\n" % _("(no help text available)"))
21796
8225bb1f0ad3 help: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents: 21289
diff changeset
502 if callable(doc):
26413
e0c572d4d112 help: pass around ui to doc loader (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26371
diff changeset
503 rst += [" %s\n" % l for l in doc(ui).splitlines()]
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
504
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
505 if not ui.verbose:
22114
3ba1d7ca3dfd help: normalize topic and extension verbose hints
Matt Mackall <mpm@selenic.com>
parents: 22113
diff changeset
506 omitted = _('(some details hidden, use --verbose'
3ba1d7ca3dfd help: normalize topic and extension verbose hints
Matt Mackall <mpm@selenic.com>
parents: 22113
diff changeset
507 ' to show complete help)')
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
508 indicateomitted(rst, omitted)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
509
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
510 try:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
511 cmdutil.findcmd(name, commands.table)
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
512 rst.append(_("\nuse 'hg help -c %s' to see help for "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
513 "the %s command\n") % (name, name))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
514 except error.UnknownCommand:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
515 pass
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
516 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
517
27378
c709b515218e help: pass sub-topic into help query functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27377
diff changeset
518 def helpext(name, subtopic=None):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
519 try:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
520 mod = extensions.find(name)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
521 doc = gettext(mod.__doc__) or _('no help text available')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
522 except KeyError:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
523 mod = None
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
524 doc = extensions.disabledext(name)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
525 if not doc:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
526 raise error.UnknownCommand(name)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
527
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
528 if '\n' not in doc:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
529 head, tail = doc, ""
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
530 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
531 head, tail = doc.split('\n', 1)
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
532 rst = [_('%s extension - %s\n\n') % (name.rpartition('.')[-1], head)]
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
533 if tail:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
534 rst.extend(tail.splitlines(True))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
535 rst.append('\n')
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
536
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
537 if not ui.verbose:
22114
3ba1d7ca3dfd help: normalize topic and extension verbose hints
Matt Mackall <mpm@selenic.com>
parents: 22113
diff changeset
538 omitted = _('(some details hidden, use --verbose'
3ba1d7ca3dfd help: normalize topic and extension verbose hints
Matt Mackall <mpm@selenic.com>
parents: 22113
diff changeset
539 ' to show complete help)')
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
540 indicateomitted(rst, omitted)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
541
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
542 if mod:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
543 try:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
544 ct = mod.cmdtable
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
545 except AttributeError:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
546 ct = {}
26845
7a77ee434179 help: replace some str.split() calls by str.partition() or str.rpartition()
Anton Shestakov <av6@dwimlabs.net>
parents: 26587
diff changeset
547 modcmds = set([c.partition('|')[0] for c in ct])
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
548 rst.extend(helplist(modcmds.__contains__))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
549 else:
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
550 rst.append(_("(use 'hg help extensions' for information on enabling"
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
551 " extensions)\n"))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
552 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
553
27378
c709b515218e help: pass sub-topic into help query functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27377
diff changeset
554 def helpextcmd(name, subtopic=None):
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
555 cmd, ext, mod = extensions.disabledcmd(ui, name,
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
556 ui.configbool('ui', 'strict'))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
557 doc = gettext(mod.__doc__).splitlines()[0]
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
558
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
559 rst = listexts(_("'%s' is provided by the following "
27152
ac27b1b3be85 help: make help deprecated mention the extension
timeless <timeless@mozdev.org>
parents: 27151
diff changeset
560 "extension:") % cmd, {ext: doc}, indent=4,
ac27b1b3be85 help: make help deprecated mention the extension
timeless <timeless@mozdev.org>
parents: 27151
diff changeset
561 showdeprecated=True)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
562 rst.append('\n')
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
563 rst.append(_("(use 'hg help extensions' for information on enabling "
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
564 "extensions)\n"))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
565 return rst
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
566
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
567
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
568 rst = []
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
569 kw = opts.get('keyword')
27325
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
570 if kw or name is None and any(opts[o] for o in opts):
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
571 matches = topicmatch(ui, name or '')
26238
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
572 helpareas = []
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
573 if opts.get('extension'):
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
574 helpareas += [('extensions', _('Extensions'))]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
575 if opts.get('command'):
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
576 helpareas += [('commands', _('Commands'))]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
577 if not helpareas:
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
578 helpareas = [('topics', _('Topics')),
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
579 ('commands', _('Commands')),
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
580 ('extensions', _('Extensions')),
26238
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
581 ('extensioncommands', _('Extension Commands'))]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
582 for t, title in helpareas:
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
583 if matches[t]:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
584 rst.append('%s:\n\n' % title)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
585 rst.extend(minirst.maketable(sorted(matches[t]), 1))
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
586 rst.append('\n')
21288
eb6eaef7ae44 help: provide a more helpful message when no keyword are matched
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20823
diff changeset
587 if not rst:
eb6eaef7ae44 help: provide a more helpful message when no keyword are matched
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20823
diff changeset
588 msg = _('no matches')
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
589 hint = _("try 'hg help' for a list of topics")
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26436
diff changeset
590 raise error.Abort(msg, hint=hint)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
591 elif name and name != 'shortlist':
26238
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
592 queries = []
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
593 if unknowncmd:
26238
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
594 queries += [helpextcmd]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
595 if opts.get('extension'):
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
596 queries += [helpext]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
597 if opts.get('command'):
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
598 queries += [helpcmd]
69da16b366ad help: fix help argument parsing and documentation
timeless@mozdev.org
parents: 26196
diff changeset
599 if not queries:
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
600 queries = (helptopic, helpcmd, helpext, helpextcmd)
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
601 for f in queries:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
602 try:
27378
c709b515218e help: pass sub-topic into help query functions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27377
diff changeset
603 rst = f(name, subtopic)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
604 break
21289
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
605 except error.UnknownCommand:
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
606 pass
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
607 else:
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
608 if unknowncmd:
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
609 raise error.UnknownCommand(name)
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
610 else:
c3784e3c3e8d help: suggest keyword search when no topic is found
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21288
diff changeset
611 msg = _('no such help topic: %s') % name
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29859
diff changeset
612 hint = _("try 'hg help --keyword %s'") % name
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26436
diff changeset
613 raise error.Abort(msg, hint=hint)
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
614 else:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
615 # program name
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
616 if not ui.quiet:
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
617 rst = [_("Mercurial Distributed SCM\n"), '\n']
27325
eadbbd14bdc1 help: fix help -c/help -e/help -k
timeless <timeless@mozdev.org>
parents: 27324
diff changeset
618 rst.extend(helplist(None, **opts))
18746
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
619
c0087d48ec3a help: move the majority of the help command to the help module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 17837
diff changeset
620 return ''.join(rst)
31059
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
621
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
622 def formattedhelp(ui, name, keep=None, unknowncmd=False, full=True, **opts):
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
623 """get help for a given topic (as a dotted name) as rendered rst
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
624
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
625 Either returns the rendered help text or raises an exception.
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
626 """
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
627 if keep is None:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
628 keep = []
31265
79715ba22f9c help: avoid mutating passed-in `keep` list in `formattedhelp`
Augie Fackler <augie@google.com>
parents: 31129
diff changeset
629 else:
79715ba22f9c help: avoid mutating passed-in `keep` list in `formattedhelp`
Augie Fackler <augie@google.com>
parents: 31129
diff changeset
630 keep = list(keep) # make a copy so we can mutate this later
31059
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
631 fullname = name
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
632 section = None
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
633 subtopic = None
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
634 if name and '.' in name:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
635 name, remaining = name.split('.', 1)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
636 remaining = encoding.lower(remaining)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
637 if '.' in remaining:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
638 subtopic, section = remaining.split('.', 1)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
639 else:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
640 if name in subtopics:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
641 subtopic = remaining
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
642 else:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
643 section = remaining
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
644 textwidth = ui.configint('ui', 'textwidth', 78)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
645 termwidth = ui.termwidth() - 2
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
646 if textwidth <= 0 or termwidth < textwidth:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
647 textwidth = termwidth
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
648 text = help_(ui, name,
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
649 subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
650
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
651 formatted, pruned = minirst.format(text, textwidth, keep=keep,
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
652 section=section)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
653
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
654 # We could have been given a weird ".foo" section without a name
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
655 # to look for, or we could have simply failed to found "foo.bar"
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
656 # because bar isn't a section of foo
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
657 if section and not (formatted and name):
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
658 raise error.Abort(_("help section not found: %s") % fullname)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
659
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
660 if 'verbose' in pruned:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
661 keep.append('omitted')
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
662 else:
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
663 keep.append('notomitted')
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
664 formatted, pruned = minirst.format(text, textwidth, keep=keep,
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
665 section=section)
2a0c8e3636b0 help: move rst formatting of help documents into help.py
Augie Fackler <augie@google.com>
parents: 30812
diff changeset
666 return formatted