2006-12-06 01:06:13 +03:00
|
|
|
# help.py - help data for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2006 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-12-06 01:06:13 +03:00
|
|
|
|
2015-12-22 08:33:27 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
import os
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
from .i18n import (
|
|
|
|
_,
|
|
|
|
gettext,
|
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
cmdutil,
|
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
extensions,
|
|
|
|
filemerge,
|
|
|
|
fileset,
|
|
|
|
minirst,
|
2017-04-27 22:19:30 +03:00
|
|
|
pycompat,
|
2015-12-22 08:33:27 +03:00
|
|
|
revset,
|
|
|
|
templatefilters,
|
|
|
|
templatekw,
|
|
|
|
templater,
|
|
|
|
util,
|
|
|
|
)
|
|
|
|
from .hgweb import (
|
|
|
|
webcommands,
|
|
|
|
)
|
2009-06-20 22:55:43 +04:00
|
|
|
|
2017-02-11 03:56:29 +03:00
|
|
|
_exclkeywords = {
|
2016-11-01 17:50:45 +03:00
|
|
|
"(ADVANCED)",
|
2015-09-26 05:38:39 +03:00
|
|
|
"(DEPRECATED)",
|
|
|
|
"(EXPERIMENTAL)",
|
2016-11-01 17:50:45 +03:00
|
|
|
# i18n: "(ADVANCED)" is a keyword, must be translated consistently
|
|
|
|
_("(ADVANCED)"),
|
2015-09-26 05:38:39 +03:00
|
|
|
# i18n: "(DEPRECATED)" is a keyword, must be translated consistently
|
|
|
|
_("(DEPRECATED)"),
|
|
|
|
# i18n: "(EXPERIMENTAL)" is a keyword, must be translated consistently
|
|
|
|
_("(EXPERIMENTAL)"),
|
2017-02-11 03:56:29 +03:00
|
|
|
}
|
2015-09-26 05:25:38 +03:00
|
|
|
|
2014-02-28 00:39:07 +04:00
|
|
|
def listexts(header, exts, indent=1, showdeprecated=False):
|
2009-06-21 19:52:30 +04:00
|
|
|
'''return a text listing of the given extensions'''
|
2012-06-02 13:22:33 +04:00
|
|
|
rst = []
|
|
|
|
if exts:
|
|
|
|
for name, desc in sorted(exts.iteritems()):
|
2015-09-26 05:50:47 +03:00
|
|
|
if not showdeprecated and any(w in desc for w in _exclkeywords):
|
2014-02-28 00:39:07 +04:00
|
|
|
continue
|
2012-06-02 13:22:33 +04:00
|
|
|
rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
|
2015-11-30 23:44:22 +03:00
|
|
|
if rst:
|
|
|
|
rst.insert(0, '\n%s\n\n' % header)
|
2012-06-02 13:22:33 +04:00
|
|
|
return rst
|
2009-06-20 22:55:49 +04:00
|
|
|
|
2015-09-26 06:06:30 +03:00
|
|
|
def extshelp(ui):
|
|
|
|
rst = loaddoc('extensions')(ui).splitlines(True)
|
2014-02-28 00:39:07 +04:00
|
|
|
rst.extend(listexts(
|
|
|
|
_('enabled extensions:'), extensions.enabled(), showdeprecated=True))
|
2012-06-02 13:22:33 +04:00
|
|
|
rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
|
|
|
|
doc = ''.join(rst)
|
2009-06-20 22:55:43 +04:00
|
|
|
return doc
|
2008-09-09 23:32:39 +04:00
|
|
|
|
2014-08-12 12:53:33 +04:00
|
|
|
def optrst(header, options, verbose):
|
2012-05-23 00:08:41 +04:00
|
|
|
data = []
|
|
|
|
multioccur = False
|
|
|
|
for option in options:
|
|
|
|
if len(option) == 5:
|
|
|
|
shortopt, longopt, default, desc, optlabel = option
|
|
|
|
else:
|
|
|
|
shortopt, longopt, default, desc = option
|
|
|
|
optlabel = _("VALUE") # default label
|
|
|
|
|
2015-09-26 05:25:38 +03:00
|
|
|
if not verbose and any(w in desc for w in _exclkeywords):
|
2012-05-23 00:08:41 +04:00
|
|
|
continue
|
|
|
|
|
|
|
|
so = ''
|
|
|
|
if shortopt:
|
|
|
|
so = '-' + shortopt
|
|
|
|
lo = '--' + longopt
|
|
|
|
if default:
|
|
|
|
desc += _(" (default: %s)") % default
|
|
|
|
|
|
|
|
if isinstance(default, list):
|
|
|
|
lo += " %s [+]" % optlabel
|
|
|
|
multioccur = True
|
|
|
|
elif (default is not None) and not isinstance(default, bool):
|
|
|
|
lo += " %s" % optlabel
|
|
|
|
|
|
|
|
data.append((so, lo, desc))
|
|
|
|
|
2014-08-12 13:00:42 +04:00
|
|
|
if multioccur:
|
|
|
|
header += (_(" ([+] can be repeated)"))
|
|
|
|
|
2014-08-12 12:53:33 +04:00
|
|
|
rst = ['\n%s:\n\n' % header]
|
|
|
|
rst.extend(minirst.maketable(data, 1))
|
2012-05-23 00:08:41 +04:00
|
|
|
|
2012-06-01 13:58:23 +04:00
|
|
|
return ''.join(rst)
|
2012-05-23 00:08:41 +04:00
|
|
|
|
help: indicate help omitting if help document is not fully displayed
Before this patch, there is no information about whether help document
is fully displayed or not.
So, some users seem to misunderstand "-v" for "hg help" just as "the
option to show list of global options": experience on "hg help -v" for
some commands not containing verbose containers may strengthen this
misunderstanding.
Such users have less opportunity for noticing omitted help document,
and this may cause insufficient understanding about Mercurial.
This patch indicates help omitting, if help document is not fully
displayed.
For command help, the message below is displayed at the end of help
output, if help document is not fully displayed:
use "hg -v help xxxx" to show more complete help and the global
options
and otherwise:
use "hg -v help xxxx" to show the global options
For topics and extensions help, the message below is displayed, only
if help document is not fully displayed:
use "hg help -v xxxx" to show more complete help
This allows users to know whether there is any omitted information or
not exactly, and can trigger "hg help -v" invocation.
This patch causes formatting help document twice, to switch messages
one for omitted help, and another for not omitted. This decreases
performance of help document formatting, but it is not mainly focused
at help command invocation, so this wouldn't become problem.
2012-10-18 05:31:15 +04:00
|
|
|
def indicateomitted(rst, omitted, notomitted=None):
|
|
|
|
rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted)
|
|
|
|
if notomitted:
|
|
|
|
rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted)
|
|
|
|
|
2015-12-09 22:09:06 +03:00
|
|
|
def filtercmd(ui, cmd, kw, doc):
|
|
|
|
if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
|
|
|
|
return True
|
|
|
|
if not ui.verbose and doc and any(w in doc for w in _exclkeywords):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-09-26 06:06:30 +03:00
|
|
|
def topicmatch(ui, kw):
|
2012-05-13 13:27:08 +04:00
|
|
|
"""Return help topics matching kw.
|
|
|
|
|
|
|
|
Returns {'section': [(name, summary), ...], ...} where section is
|
|
|
|
one of topics, commands, extensions, or extensioncommands.
|
|
|
|
"""
|
|
|
|
kw = encoding.lower(kw)
|
|
|
|
def lowercontains(container):
|
2012-06-04 10:45:56 +04:00
|
|
|
return kw in encoding.lower(container) # translated in helptable
|
2012-05-13 13:27:08 +04:00
|
|
|
results = {'topics': [],
|
|
|
|
'commands': [],
|
|
|
|
'extensions': [],
|
|
|
|
'extensioncommands': [],
|
|
|
|
}
|
|
|
|
for names, header, doc in helptable:
|
2014-08-30 22:06:24 +04:00
|
|
|
# Old extensions may use a str as doc.
|
2012-05-13 13:27:08 +04:00
|
|
|
if (sum(map(lowercontains, names))
|
|
|
|
or lowercontains(header)
|
2015-09-26 06:06:30 +03:00
|
|
|
or (callable(doc) and lowercontains(doc(ui)))):
|
2012-05-13 13:27:08 +04:00
|
|
|
results['topics'].append((names[0], header))
|
2015-12-22 08:33:27 +03:00
|
|
|
from . import commands # avoid cycle
|
2012-05-13 13:27:08 +04:00
|
|
|
for cmd, entry in commands.table.iteritems():
|
|
|
|
if len(entry) == 3:
|
|
|
|
summary = entry[2]
|
|
|
|
else:
|
|
|
|
summary = ''
|
2012-06-04 10:45:56 +04:00
|
|
|
# translate docs *before* searching there
|
|
|
|
docs = _(getattr(entry[0], '__doc__', None)) or ''
|
2012-05-13 13:27:08 +04:00
|
|
|
if kw in cmd or lowercontains(summary) or lowercontains(docs):
|
2012-06-04 10:45:56 +04:00
|
|
|
doclines = docs.splitlines()
|
2012-05-13 13:27:08 +04:00
|
|
|
if doclines:
|
|
|
|
summary = doclines[0]
|
2015-11-02 18:37:14 +03:00
|
|
|
cmdname = cmd.partition('|')[0].lstrip('^')
|
2015-12-09 22:09:35 +03:00
|
|
|
if filtercmd(ui, cmdname, kw, docs):
|
|
|
|
continue
|
2012-05-13 13:27:08 +04:00
|
|
|
results['commands'].append((cmdname, summary))
|
|
|
|
for name, docs in itertools.chain(
|
2013-09-23 15:23:25 +04:00
|
|
|
extensions.enabled(False).iteritems(),
|
2012-05-13 13:27:08 +04:00
|
|
|
extensions.disabled().iteritems()):
|
2016-02-10 12:48:58 +03:00
|
|
|
if not docs:
|
|
|
|
continue
|
2015-12-17 13:30:17 +03:00
|
|
|
mod = extensions.load(ui, name, '')
|
2015-11-02 18:37:14 +03:00
|
|
|
name = name.rpartition('.')[-1]
|
2012-05-13 13:27:08 +04:00
|
|
|
if lowercontains(name) or lowercontains(docs):
|
2012-06-04 10:45:56 +04:00
|
|
|
# extension docs are already translated
|
|
|
|
results['extensions'].append((name, docs.splitlines()[0]))
|
2012-05-13 13:27:08 +04:00
|
|
|
for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
|
2012-05-13 15:03:11 +04:00
|
|
|
if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
|
2015-11-02 18:37:14 +03:00
|
|
|
cmdname = cmd.partition('|')[0].lstrip('^')
|
2012-06-07 03:42:50 +04:00
|
|
|
if entry[0].__doc__:
|
|
|
|
cmddoc = gettext(entry[0].__doc__).splitlines()[0]
|
2012-06-07 17:54:40 +04:00
|
|
|
else:
|
|
|
|
cmddoc = _('(no help text available)')
|
2015-12-14 08:29:55 +03:00
|
|
|
if filtercmd(ui, cmdname, kw, cmddoc):
|
|
|
|
continue
|
2012-06-07 17:54:40 +04:00
|
|
|
results['extensioncommands'].append((cmdname, cmddoc))
|
2012-05-13 13:27:08 +04:00
|
|
|
return results
|
|
|
|
|
2015-12-13 21:45:27 +03:00
|
|
|
def loaddoc(topic, subdir=None):
|
2009-10-04 11:59:13 +04:00
|
|
|
"""Return a delayed loader for help/topic.txt."""
|
2007-12-05 14:40:01 +03:00
|
|
|
|
2015-09-26 06:06:30 +03:00
|
|
|
def loader(ui):
|
2014-09-28 18:57:47 +04:00
|
|
|
docdir = os.path.join(util.datapath, 'help')
|
2015-12-13 21:45:27 +03:00
|
|
|
if subdir:
|
|
|
|
docdir = os.path.join(docdir, subdir)
|
2009-10-04 11:59:13 +04:00
|
|
|
path = os.path.join(docdir, topic + ".txt")
|
2011-05-02 12:11:18 +04:00
|
|
|
doc = gettext(util.readfile(path))
|
2010-10-23 21:21:49 +04:00
|
|
|
for rewriter in helphooks.get(topic, []):
|
2015-09-26 06:11:46 +03:00
|
|
|
doc = rewriter(ui, topic, doc)
|
2010-10-23 21:21:49 +04:00
|
|
|
return doc
|
|
|
|
|
2009-10-04 11:59:13 +04:00
|
|
|
return loader
|
2009-01-22 21:02:50 +03:00
|
|
|
|
2015-12-13 21:35:03 +03:00
|
|
|
internalstable = sorted([
|
2016-08-07 03:04:22 +03:00
|
|
|
(['bundles'], _('Bundles'),
|
2015-12-13 21:35:03 +03:00
|
|
|
loaddoc('bundles', subdir='internals')),
|
2017-03-11 01:37:39 +03:00
|
|
|
(['censor'], _('Censor'),
|
|
|
|
loaddoc('censor', subdir='internals')),
|
2016-08-07 03:04:22 +03:00
|
|
|
(['changegroups'], _('Changegroups'),
|
2015-12-13 21:35:03 +03:00
|
|
|
loaddoc('changegroups', subdir='internals')),
|
2016-08-07 03:04:22 +03:00
|
|
|
(['requirements'], _('Repository Requirements'),
|
2016-03-13 05:51:07 +03:00
|
|
|
loaddoc('requirements', subdir='internals')),
|
2016-08-07 03:04:22 +03:00
|
|
|
(['revlogs'], _('Revision Logs'),
|
2015-12-31 02:21:57 +03:00
|
|
|
loaddoc('revlogs', subdir='internals')),
|
2016-08-23 05:46:39 +03:00
|
|
|
(['wireprotocol'], _('Wire Protocol'),
|
|
|
|
loaddoc('wireprotocol', subdir='internals')),
|
2015-12-13 21:35:03 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
def internalshelp(ui):
|
|
|
|
"""Generate the index for the "internals" topic."""
|
2017-04-20 03:04:22 +03:00
|
|
|
lines = ['To access a subtopic, use "hg help internals.{subtopic-name}"\n',
|
|
|
|
'\n']
|
2015-12-13 21:35:03 +03:00
|
|
|
for names, header, doc in internalstable:
|
2015-12-17 16:29:41 +03:00
|
|
|
lines.append(' :%s: %s\n' % (names[0], header))
|
2015-12-13 21:35:03 +03:00
|
|
|
|
2015-12-17 16:29:41 +03:00
|
|
|
return ''.join(lines)
|
2015-12-13 21:35:03 +03:00
|
|
|
|
2011-04-05 08:40:47 +04:00
|
|
|
helptable = sorted([
|
2017-04-01 23:42:06 +03:00
|
|
|
(['bundlespec'], _("Bundle File Formats"), loaddoc('bundlespec')),
|
2017-03-01 22:22:04 +03:00
|
|
|
(['color'], _("Colorizing Outputs"), loaddoc('color')),
|
2010-09-02 14:53:28 +04:00
|
|
|
(["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(["dates"], _("Date Formats"), loaddoc('dates')),
|
|
|
|
(["patterns"], _("File Name Patterns"), loaddoc('patterns')),
|
2010-01-25 09:05:27 +03:00
|
|
|
(['environment', 'env'], _('Environment Variables'),
|
|
|
|
loaddoc('environment')),
|
2017-01-11 22:37:38 +03:00
|
|
|
(['revisions', 'revs', 'revsets', 'revset', 'multirevs', 'mrevs'],
|
|
|
|
_('Specifying Revisions'), loaddoc('revisions')),
|
2012-08-01 16:59:15 +04:00
|
|
|
(['filesets', 'fileset'], _("Specifying File Sets"), loaddoc('filesets')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['diffs'], _('Diff Formats'), loaddoc('diffs')),
|
2017-01-14 08:21:02 +03:00
|
|
|
(['merge-tools', 'mergetools', 'mergetool'], _('Merge Tools'),
|
|
|
|
loaddoc('merge-tools')),
|
2012-05-02 01:14:51 +04:00
|
|
|
(['templating', 'templates', 'template', 'style'], _('Template Usage'),
|
2010-01-25 09:05:27 +03:00
|
|
|
loaddoc('templates')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(['urls'], _('URL Paths'), loaddoc('urls')),
|
2012-04-30 13:51:24 +04:00
|
|
|
(["extensions"], _("Using Additional Features"), extshelp),
|
2012-08-01 16:59:15 +04:00
|
|
|
(["subrepos", "subrepo"], _("Subrepositories"), loaddoc('subrepos')),
|
2012-08-01 02:18:23 +04:00
|
|
|
(["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
|
|
|
|
(["glossary"], _("Glossary"), loaddoc('glossary')),
|
|
|
|
(["hgignore", "ignore"], _("Syntax for Mercurial Ignore Files"),
|
|
|
|
loaddoc('hgignore')),
|
|
|
|
(["phases"], _("Working with Phases"), loaddoc('phases')),
|
2015-07-19 03:10:28 +03:00
|
|
|
(['scripting'], _('Using Mercurial from scripts and automation'),
|
|
|
|
loaddoc('scripting')),
|
2015-12-13 21:35:03 +03:00
|
|
|
(['internals'], _("Technical implementation topics"),
|
|
|
|
internalshelp),
|
2017-02-07 08:07:53 +03:00
|
|
|
(['pager'], _("Pager Support"), loaddoc('pager')),
|
2011-04-05 08:40:47 +04:00
|
|
|
])
|
2010-10-23 21:21:49 +04:00
|
|
|
|
2015-12-13 22:19:55 +03:00
|
|
|
# Maps topics with sub-topics to a list of their sub-topics.
|
|
|
|
subtopics = {
|
|
|
|
'internals': internalstable,
|
|
|
|
}
|
|
|
|
|
2010-10-23 21:21:49 +04:00
|
|
|
# Map topics to lists of callable taking the current topic help and
|
|
|
|
# returning the updated version
|
2011-05-13 21:57:27 +04:00
|
|
|
helphooks = {}
|
2010-10-23 21:21:49 +04:00
|
|
|
|
|
|
|
def addtopichook(topic, rewriter):
|
|
|
|
helphooks.setdefault(topic, []).append(rewriter)
|
2011-03-12 14:46:31 +03:00
|
|
|
|
2015-09-26 06:11:46 +03:00
|
|
|
def makeitemsdoc(ui, topic, doc, marker, items, dedent=False):
|
2011-03-12 14:46:31 +03:00
|
|
|
"""Extract docstring from the items key to function mapping, build a
|
2015-08-31 01:54:31 +03:00
|
|
|
single documentation block and use it to overwrite the marker in doc.
|
2011-03-12 14:46:31 +03:00
|
|
|
"""
|
|
|
|
entries = []
|
|
|
|
for name in sorted(items):
|
|
|
|
text = (items[name].__doc__ or '').rstrip()
|
2015-09-26 06:17:44 +03:00
|
|
|
if (not text
|
|
|
|
or not ui.verbose and any(w in text for w in _exclkeywords)):
|
2011-03-12 14:46:31 +03:00
|
|
|
continue
|
|
|
|
text = gettext(text)
|
help: teach topic symbols how to dedent
When using docstrings for documenting symbols such as revsets,
templates, or hgweb commands, documentation likely has leading
whitespace corresponding to the indentation from the Python source
file.
Up until this point, the help system stripped all leading and
trailing whitespace and replaced it with 2 spaces of leading
whitespace. There were a few bad side-effects. First, sections
could not be used in docstrings because they would be indented
and the rst parser would fail to parse them as sections. Also,
any rst elements that required indentation would lose their
indentation, again causing them to be parsed and rendered
incorrectly.
In this patch, we teach the topic symbols system how to dedent
text properly. I argue this mode should be enabled by default.
However, I stopped short of changing that because it would cause
a lot of documentation reformatting to occur. I'm not sure if
people are relying on or wanting indentation. So, dedenting has
only been turned on for hgweb symbols. This decision should be
scrutinized.
2015-02-10 01:59:04 +03:00
|
|
|
if dedent:
|
|
|
|
text = textwrap.dedent(text)
|
2011-03-12 14:46:31 +03:00
|
|
|
lines = text.splitlines()
|
2012-03-10 01:54:17 +04:00
|
|
|
doclines = [(lines[0])]
|
|
|
|
for l in lines[1:]:
|
|
|
|
# Stop once we find some Python doctest
|
|
|
|
if l.strip().startswith('>>>'):
|
|
|
|
break
|
help: teach topic symbols how to dedent
When using docstrings for documenting symbols such as revsets,
templates, or hgweb commands, documentation likely has leading
whitespace corresponding to the indentation from the Python source
file.
Up until this point, the help system stripped all leading and
trailing whitespace and replaced it with 2 spaces of leading
whitespace. There were a few bad side-effects. First, sections
could not be used in docstrings because they would be indented
and the rst parser would fail to parse them as sections. Also,
any rst elements that required indentation would lose their
indentation, again causing them to be parsed and rendered
incorrectly.
In this patch, we teach the topic symbols system how to dedent
text properly. I argue this mode should be enabled by default.
However, I stopped short of changing that because it would cause
a lot of documentation reformatting to occur. I'm not sure if
people are relying on or wanting indentation. So, dedenting has
only been turned on for hgweb symbols. This decision should be
scrutinized.
2015-02-10 01:59:04 +03:00
|
|
|
if dedent:
|
|
|
|
doclines.append(l.rstrip())
|
|
|
|
else:
|
|
|
|
doclines.append(' ' + l.strip())
|
2012-03-10 01:54:17 +04:00
|
|
|
entries.append('\n'.join(doclines))
|
2011-03-12 14:46:31 +03:00
|
|
|
entries = '\n\n'.join(entries)
|
|
|
|
return doc.replace(marker, entries)
|
2011-05-13 21:57:27 +04:00
|
|
|
|
help: teach topic symbols how to dedent
When using docstrings for documenting symbols such as revsets,
templates, or hgweb commands, documentation likely has leading
whitespace corresponding to the indentation from the Python source
file.
Up until this point, the help system stripped all leading and
trailing whitespace and replaced it with 2 spaces of leading
whitespace. There were a few bad side-effects. First, sections
could not be used in docstrings because they would be indented
and the rst parser would fail to parse them as sections. Also,
any rst elements that required indentation would lose their
indentation, again causing them to be parsed and rendered
incorrectly.
In this patch, we teach the topic symbols system how to dedent
text properly. I argue this mode should be enabled by default.
However, I stopped short of changing that because it would cause
a lot of documentation reformatting to occur. I'm not sure if
people are relying on or wanting indentation. So, dedenting has
only been turned on for hgweb symbols. This decision should be
scrutinized.
2015-02-10 01:59:04 +03:00
|
|
|
def addtopicsymbols(topic, marker, symbols, dedent=False):
|
2015-09-26 06:11:46 +03:00
|
|
|
def add(ui, topic, doc):
|
|
|
|
return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent)
|
2011-05-13 21:57:27 +04:00
|
|
|
addtopichook(topic, add)
|
|
|
|
|
2017-04-01 23:42:06 +03:00
|
|
|
addtopicsymbols('bundlespec', '.. bundlecompressionmarker',
|
|
|
|
util.bundlecompressiontopics())
|
2011-06-19 01:53:49 +04:00
|
|
|
addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols)
|
2015-02-10 10:07:39 +03:00
|
|
|
addtopicsymbols('merge-tools', '.. internaltoolsmarker',
|
|
|
|
filemerge.internalsdoc)
|
2017-01-11 22:37:38 +03:00
|
|
|
addtopicsymbols('revisions', '.. predicatesmarker', revset.symbols)
|
2015-09-26 06:39:13 +03:00
|
|
|
addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords)
|
2011-05-13 21:57:27 +04:00
|
|
|
addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)
|
2015-04-02 06:23:58 +03:00
|
|
|
addtopicsymbols('templates', '.. functionsmarker', templater.funcs)
|
help: teach topic symbols how to dedent
When using docstrings for documenting symbols such as revsets,
templates, or hgweb commands, documentation likely has leading
whitespace corresponding to the indentation from the Python source
file.
Up until this point, the help system stripped all leading and
trailing whitespace and replaced it with 2 spaces of leading
whitespace. There were a few bad side-effects. First, sections
could not be used in docstrings because they would be indented
and the rst parser would fail to parse them as sections. Also,
any rst elements that required indentation would lose their
indentation, again causing them to be parsed and rendered
incorrectly.
In this patch, we teach the topic symbols system how to dedent
text properly. I argue this mode should be enabled by default.
However, I stopped short of changing that because it would cause
a lot of documentation reformatting to occur. I'm not sure if
people are relying on or wanting indentation. So, dedenting has
only been turned on for hgweb symbols. This decision should be
scrutinized.
2015-02-10 01:59:04 +03:00
|
|
|
addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands,
|
|
|
|
dedent=True)
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2015-12-13 22:04:45 +03:00
|
|
|
def help_(ui, name, unknowncmd=False, full=True, subtopic=None, **opts):
|
2013-02-10 01:51:21 +04:00
|
|
|
'''
|
|
|
|
Generate the help for 'name' as unformatted restructured text. If
|
|
|
|
'name' is None, describe the commands available.
|
|
|
|
'''
|
|
|
|
|
2015-12-22 08:33:27 +03:00
|
|
|
from . import commands # avoid cycle
|
2017-04-27 22:19:30 +03:00
|
|
|
opts = pycompat.byteskwargs(opts)
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2015-12-13 22:29:01 +03:00
|
|
|
def helpcmd(name, subtopic=None):
|
2013-02-10 01:51:21 +04:00
|
|
|
try:
|
|
|
|
aliases, entry = cmdutil.findcmd(name, commands.table,
|
|
|
|
strict=unknowncmd)
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.AmbiguousCommand as inst:
|
2013-02-10 01:51:21 +04:00
|
|
|
# py3k fix: except vars can't be used outside the scope of the
|
|
|
|
# except block, nor can be used inside a lambda. python issue4617
|
|
|
|
prefix = inst.args[0]
|
|
|
|
select = lambda c: c.lstrip('^').startswith(prefix)
|
|
|
|
rst = helplist(select)
|
|
|
|
return rst
|
|
|
|
|
|
|
|
rst = []
|
|
|
|
|
|
|
|
# check if it's an invalid alias and display its error if it is
|
2014-05-17 16:13:31 +04:00
|
|
|
if getattr(entry[0], 'badalias', None):
|
2014-08-13 14:38:47 +04:00
|
|
|
rst.append(entry[0].badalias + '\n')
|
|
|
|
if entry[0].unknowncmd:
|
|
|
|
try:
|
|
|
|
rst.extend(helpextcmd(entry[0].cmdname))
|
|
|
|
except error.UnknownCommand:
|
|
|
|
pass
|
2013-02-10 01:51:21 +04:00
|
|
|
return rst
|
|
|
|
|
|
|
|
# synopsis
|
|
|
|
if len(entry) > 2:
|
|
|
|
if entry[2].startswith('hg'):
|
|
|
|
rst.append("%s\n" % entry[2])
|
|
|
|
else:
|
|
|
|
rst.append('hg %s %s\n' % (aliases[0], entry[2]))
|
|
|
|
else:
|
|
|
|
rst.append('hg %s\n' % aliases[0])
|
|
|
|
# aliases
|
|
|
|
if full and not ui.quiet and len(aliases) > 1:
|
|
|
|
rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:]))
|
|
|
|
rst.append('\n')
|
|
|
|
|
|
|
|
# description
|
|
|
|
doc = gettext(entry[0].__doc__)
|
|
|
|
if not doc:
|
|
|
|
doc = _("(no help text available)")
|
|
|
|
if util.safehasattr(entry[0], 'definition'): # aliased command
|
2016-04-08 21:35:49 +03:00
|
|
|
source = entry[0].source
|
2013-02-10 01:51:21 +04:00
|
|
|
if entry[0].definition.startswith('!'): # shell alias
|
2016-04-08 21:35:49 +03:00
|
|
|
doc = (_('shell alias for::\n\n %s\n\ndefined by: %s\n') %
|
|
|
|
(entry[0].definition[1:], source))
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
2016-04-08 21:35:49 +03:00
|
|
|
doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') %
|
|
|
|
(entry[0].definition, doc, source))
|
2013-02-10 01:51:21 +04:00
|
|
|
doc = doc.splitlines(True)
|
|
|
|
if ui.quiet or not full:
|
|
|
|
rst.append(doc[0])
|
|
|
|
else:
|
|
|
|
rst.extend(doc)
|
|
|
|
rst.append('\n')
|
|
|
|
|
|
|
|
# check if this command shadows a non-trivial (multi-line)
|
|
|
|
# extension help text
|
|
|
|
try:
|
|
|
|
mod = extensions.find(name)
|
|
|
|
doc = gettext(mod.__doc__) or ''
|
|
|
|
if '\n' in doc.strip():
|
2016-09-21 02:47:46 +03:00
|
|
|
msg = _("(use 'hg help -e %s' to show help for "
|
|
|
|
"the %s extension)") % (name, name)
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.append('\n%s\n' % msg)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# options
|
|
|
|
if not ui.quiet and entry[1]:
|
2014-08-12 12:53:33 +04:00
|
|
|
rst.append(optrst(_("options"), entry[1], ui.verbose))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
if ui.verbose:
|
2014-08-12 12:53:33 +04:00
|
|
|
rst.append(optrst(_("global options"),
|
|
|
|
commands.globalopts, ui.verbose))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
if not ui.verbose:
|
|
|
|
if not full:
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg %s -h' to show more help)\n")
|
2013-02-10 01:51:21 +04:00
|
|
|
% name)
|
|
|
|
elif not ui.quiet:
|
2014-08-12 12:01:37 +04:00
|
|
|
rst.append(_('\n(some details hidden, use --verbose '
|
|
|
|
'to show complete help)'))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
return rst
|
|
|
|
|
|
|
|
|
2015-12-09 08:56:54 +03:00
|
|
|
def helplist(select=None, **opts):
|
2013-02-10 01:51:21 +04:00
|
|
|
# list of commands
|
|
|
|
if name == "shortlist":
|
|
|
|
header = _('basic commands:\n\n')
|
2014-03-15 19:14:04 +04:00
|
|
|
elif name == "debug":
|
|
|
|
header = _('debug commands (internal and unsupported):\n\n')
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
|
|
|
header = _('list of commands:\n\n')
|
|
|
|
|
|
|
|
h = {}
|
|
|
|
cmds = {}
|
|
|
|
for c, e in commands.table.iteritems():
|
2015-11-02 18:37:14 +03:00
|
|
|
f = c.partition("|")[0]
|
2013-02-10 01:51:21 +04:00
|
|
|
if select and not select(f):
|
|
|
|
continue
|
|
|
|
if (not select and name != 'shortlist' and
|
|
|
|
e[0].__module__ != commands.__name__):
|
|
|
|
continue
|
|
|
|
if name == "shortlist" and not f.startswith("^"):
|
|
|
|
continue
|
|
|
|
f = f.lstrip("^")
|
|
|
|
doc = e[0].__doc__
|
2015-12-09 22:09:06 +03:00
|
|
|
if filtercmd(ui, f, name, doc):
|
2013-02-10 01:51:21 +04:00
|
|
|
continue
|
|
|
|
doc = gettext(doc)
|
|
|
|
if not doc:
|
|
|
|
doc = _("(no help text available)")
|
|
|
|
h[f] = doc.splitlines()[0].rstrip()
|
|
|
|
cmds[f] = c.lstrip("^")
|
|
|
|
|
|
|
|
rst = []
|
|
|
|
if not h:
|
|
|
|
if not ui.quiet:
|
|
|
|
rst.append(_('no commands defined\n'))
|
|
|
|
return rst
|
|
|
|
|
|
|
|
if not ui.quiet:
|
|
|
|
rst.append(header)
|
|
|
|
fns = sorted(h)
|
|
|
|
for f in fns:
|
|
|
|
if ui.verbose:
|
|
|
|
commacmds = cmds[f].replace("|",", ")
|
|
|
|
rst.append(" :%s: %s\n" % (commacmds, h[f]))
|
|
|
|
else:
|
|
|
|
rst.append(' :%s: %s\n' % (f, h[f]))
|
|
|
|
|
2015-12-09 08:56:54 +03:00
|
|
|
ex = opts.get
|
|
|
|
anyopts = (ex('keyword') or not (ex('command') or ex('extension')))
|
|
|
|
if not name and anyopts:
|
2013-02-10 01:51:21 +04:00
|
|
|
exts = listexts(_('enabled extensions:'), extensions.enabled())
|
|
|
|
if exts:
|
|
|
|
rst.append('\n')
|
|
|
|
rst.extend(exts)
|
|
|
|
|
|
|
|
rst.append(_("\nadditional help topics:\n\n"))
|
|
|
|
topics = []
|
|
|
|
for names, header, doc in helptable:
|
|
|
|
topics.append((names[0], header))
|
|
|
|
for t, desc in topics:
|
|
|
|
rst.append(" :%s: %s\n" % (t, desc))
|
|
|
|
|
2014-08-12 12:42:09 +04:00
|
|
|
if ui.quiet:
|
|
|
|
pass
|
|
|
|
elif ui.verbose:
|
2014-08-12 12:53:33 +04:00
|
|
|
rst.append('\n%s\n' % optrst(_("global options"),
|
|
|
|
commands.globalopts, ui.verbose))
|
2014-08-12 12:42:09 +04:00
|
|
|
if name == 'shortlist':
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg help' for the full list "
|
|
|
|
"of commands)\n"))
|
2014-08-12 12:42:09 +04:00
|
|
|
else:
|
|
|
|
if name == 'shortlist':
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg help' for the full list of commands "
|
|
|
|
"or 'hg -v' for details)\n"))
|
2014-08-12 12:42:09 +04:00
|
|
|
elif name and not full:
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg help %s' to show the full help "
|
|
|
|
"text)\n") % name)
|
2014-12-22 05:20:50 +03:00
|
|
|
elif name and cmds and name in cmds.keys():
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg help -v -e %s' to show built-in "
|
|
|
|
"aliases and global options)\n") % name)
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\n(use 'hg help -v%s' to show built-in aliases "
|
|
|
|
"and global options)\n")
|
2014-08-12 13:11:32 +04:00
|
|
|
% (name and " " + name or ""))
|
2013-02-10 01:51:21 +04:00
|
|
|
return rst
|
|
|
|
|
2015-12-13 22:29:01 +03:00
|
|
|
def helptopic(name, subtopic=None):
|
2015-12-13 22:19:55 +03:00
|
|
|
# Look for sub-topic entry first.
|
|
|
|
header, doc = None, None
|
|
|
|
if subtopic and name in subtopics:
|
|
|
|
for names, header, doc in subtopics[name]:
|
|
|
|
if subtopic in names:
|
|
|
|
break
|
|
|
|
|
|
|
|
if not header:
|
|
|
|
for names, header, doc in helptable:
|
|
|
|
if name in names:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise error.UnknownCommand(name)
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2013-02-10 15:58:57 +04:00
|
|
|
rst = [minirst.section(header)]
|
|
|
|
|
2013-02-10 01:51:21 +04:00
|
|
|
# description
|
|
|
|
if not doc:
|
|
|
|
rst.append(" %s\n" % _("(no help text available)"))
|
2014-06-23 17:24:24 +04:00
|
|
|
if callable(doc):
|
2015-09-26 06:06:30 +03:00
|
|
|
rst += [" %s\n" % l for l in doc(ui).splitlines()]
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
if not ui.verbose:
|
2014-08-12 12:25:51 +04:00
|
|
|
omitted = _('(some details hidden, use --verbose'
|
|
|
|
' to show complete help)')
|
2013-02-10 01:51:21 +04:00
|
|
|
indicateomitted(rst, omitted)
|
|
|
|
|
|
|
|
try:
|
|
|
|
cmdutil.findcmd(name, commands.table)
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("\nuse 'hg help -c %s' to see help for "
|
|
|
|
"the %s command\n") % (name, name))
|
2013-02-10 01:51:21 +04:00
|
|
|
except error.UnknownCommand:
|
|
|
|
pass
|
|
|
|
return rst
|
|
|
|
|
2015-12-13 22:29:01 +03:00
|
|
|
def helpext(name, subtopic=None):
|
2013-02-10 01:51:21 +04:00
|
|
|
try:
|
|
|
|
mod = extensions.find(name)
|
|
|
|
doc = gettext(mod.__doc__) or _('no help text available')
|
|
|
|
except KeyError:
|
|
|
|
mod = None
|
|
|
|
doc = extensions.disabledext(name)
|
|
|
|
if not doc:
|
|
|
|
raise error.UnknownCommand(name)
|
|
|
|
|
|
|
|
if '\n' not in doc:
|
|
|
|
head, tail = doc, ""
|
|
|
|
else:
|
|
|
|
head, tail = doc.split('\n', 1)
|
2015-11-02 18:37:14 +03:00
|
|
|
rst = [_('%s extension - %s\n\n') % (name.rpartition('.')[-1], head)]
|
2013-02-10 01:51:21 +04:00
|
|
|
if tail:
|
|
|
|
rst.extend(tail.splitlines(True))
|
|
|
|
rst.append('\n')
|
|
|
|
|
|
|
|
if not ui.verbose:
|
2014-08-12 12:25:51 +04:00
|
|
|
omitted = _('(some details hidden, use --verbose'
|
|
|
|
' to show complete help)')
|
2013-02-10 01:51:21 +04:00
|
|
|
indicateomitted(rst, omitted)
|
|
|
|
|
|
|
|
if mod:
|
|
|
|
try:
|
|
|
|
ct = mod.cmdtable
|
|
|
|
except AttributeError:
|
|
|
|
ct = {}
|
2015-11-02 18:37:14 +03:00
|
|
|
modcmds = set([c.partition('|')[0] for c in ct])
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.extend(helplist(modcmds.__contains__))
|
|
|
|
else:
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("(use 'hg help extensions' for information on enabling"
|
|
|
|
" extensions)\n"))
|
2013-02-10 01:51:21 +04:00
|
|
|
return rst
|
|
|
|
|
2015-12-13 22:29:01 +03:00
|
|
|
def helpextcmd(name, subtopic=None):
|
2013-02-10 01:51:21 +04:00
|
|
|
cmd, ext, mod = extensions.disabledcmd(ui, name,
|
|
|
|
ui.configbool('ui', 'strict'))
|
|
|
|
doc = gettext(mod.__doc__).splitlines()[0]
|
|
|
|
|
|
|
|
rst = listexts(_("'%s' is provided by the following "
|
2015-11-30 23:45:07 +03:00
|
|
|
"extension:") % cmd, {ext: doc}, indent=4,
|
|
|
|
showdeprecated=True)
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.append('\n')
|
2016-09-21 02:47:46 +03:00
|
|
|
rst.append(_("(use 'hg help extensions' for information on enabling "
|
|
|
|
"extensions)\n"))
|
2013-02-10 01:51:21 +04:00
|
|
|
return rst
|
|
|
|
|
|
|
|
|
|
|
|
rst = []
|
|
|
|
kw = opts.get('keyword')
|
2015-12-09 08:56:54 +03:00
|
|
|
if kw or name is None and any(opts[o] for o in opts):
|
|
|
|
matches = topicmatch(ui, name or '')
|
2015-09-11 03:22:37 +03:00
|
|
|
helpareas = []
|
|
|
|
if opts.get('extension'):
|
|
|
|
helpareas += [('extensions', _('Extensions'))]
|
|
|
|
if opts.get('command'):
|
|
|
|
helpareas += [('commands', _('Commands'))]
|
|
|
|
if not helpareas:
|
|
|
|
helpareas = [('topics', _('Topics')),
|
2013-02-10 01:51:21 +04:00
|
|
|
('commands', _('Commands')),
|
|
|
|
('extensions', _('Extensions')),
|
2015-09-11 03:22:37 +03:00
|
|
|
('extensioncommands', _('Extension Commands'))]
|
|
|
|
for t, title in helpareas:
|
2013-02-10 01:51:21 +04:00
|
|
|
if matches[t]:
|
|
|
|
rst.append('%s:\n\n' % title)
|
|
|
|
rst.extend(minirst.maketable(sorted(matches[t]), 1))
|
|
|
|
rst.append('\n')
|
2014-04-17 04:01:03 +04:00
|
|
|
if not rst:
|
|
|
|
msg = _('no matches')
|
2016-09-21 02:47:46 +03:00
|
|
|
hint = _("try 'hg help' for a list of topics")
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-02-10 01:51:21 +04:00
|
|
|
elif name and name != 'shortlist':
|
2015-09-11 03:22:37 +03:00
|
|
|
queries = []
|
2013-02-10 01:51:21 +04:00
|
|
|
if unknowncmd:
|
2015-09-11 03:22:37 +03:00
|
|
|
queries += [helpextcmd]
|
|
|
|
if opts.get('extension'):
|
|
|
|
queries += [helpext]
|
|
|
|
if opts.get('command'):
|
|
|
|
queries += [helpcmd]
|
|
|
|
if not queries:
|
2013-02-10 01:51:21 +04:00
|
|
|
queries = (helptopic, helpcmd, helpext, helpextcmd)
|
|
|
|
for f in queries:
|
|
|
|
try:
|
2015-12-13 22:29:01 +03:00
|
|
|
rst = f(name, subtopic)
|
2013-02-10 01:51:21 +04:00
|
|
|
break
|
2014-04-17 03:55:40 +04:00
|
|
|
except error.UnknownCommand:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if unknowncmd:
|
|
|
|
raise error.UnknownCommand(name)
|
|
|
|
else:
|
|
|
|
msg = _('no such help topic: %s') % name
|
2016-09-21 02:47:46 +03:00
|
|
|
hint = _("try 'hg help --keyword %s'") % name
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
|
|
|
# program name
|
|
|
|
if not ui.quiet:
|
|
|
|
rst = [_("Mercurial Distributed SCM\n"), '\n']
|
2017-05-28 20:28:41 +03:00
|
|
|
rst.extend(helplist(None, **pycompat.strkwargs(opts)))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
return ''.join(rst)
|
2017-02-21 22:17:31 +03:00
|
|
|
|
|
|
|
def formattedhelp(ui, name, keep=None, unknowncmd=False, full=True, **opts):
|
|
|
|
"""get help for a given topic (as a dotted name) as rendered rst
|
|
|
|
|
|
|
|
Either returns the rendered help text or raises an exception.
|
|
|
|
"""
|
|
|
|
if keep is None:
|
|
|
|
keep = []
|
2017-03-09 02:31:33 +03:00
|
|
|
else:
|
|
|
|
keep = list(keep) # make a copy so we can mutate this later
|
2017-02-21 22:17:31 +03:00
|
|
|
fullname = name
|
|
|
|
section = None
|
|
|
|
subtopic = None
|
|
|
|
if name and '.' in name:
|
|
|
|
name, remaining = name.split('.', 1)
|
|
|
|
remaining = encoding.lower(remaining)
|
|
|
|
if '.' in remaining:
|
|
|
|
subtopic, section = remaining.split('.', 1)
|
|
|
|
else:
|
|
|
|
if name in subtopics:
|
|
|
|
subtopic = remaining
|
|
|
|
else:
|
|
|
|
section = remaining
|
|
|
|
textwidth = ui.configint('ui', 'textwidth', 78)
|
|
|
|
termwidth = ui.termwidth() - 2
|
|
|
|
if textwidth <= 0 or termwidth < textwidth:
|
|
|
|
textwidth = termwidth
|
|
|
|
text = help_(ui, name,
|
|
|
|
subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts)
|
|
|
|
|
|
|
|
formatted, pruned = minirst.format(text, textwidth, keep=keep,
|
|
|
|
section=section)
|
|
|
|
|
|
|
|
# We could have been given a weird ".foo" section without a name
|
|
|
|
# to look for, or we could have simply failed to found "foo.bar"
|
|
|
|
# because bar isn't a section of foo
|
|
|
|
if section and not (formatted and name):
|
|
|
|
raise error.Abort(_("help section not found: %s") % fullname)
|
|
|
|
|
|
|
|
if 'verbose' in pruned:
|
|
|
|
keep.append('omitted')
|
|
|
|
else:
|
|
|
|
keep.append('notomitted')
|
|
|
|
formatted, pruned = minirst.format(text, textwidth, keep=keep,
|
|
|
|
section=section)
|
|
|
|
return formatted
|