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:
|
2017-05-28 22:49:29 +03:00
|
|
|
# default is of unknown type, and in Python 2 we abused
|
|
|
|
# the %s-shows-repr property to handle integers etc. To
|
|
|
|
# match that behavior on Python 3, we do str(default) and
|
|
|
|
# then convert it to bytes.
|
|
|
|
desc += _(" (default: %s)") % pycompat.bytestr(default)
|
2012-05-23 00:08:41 +04:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
2018-05-03 14:33:07 +03:00
|
|
|
if not data:
|
|
|
|
return ''
|
|
|
|
|
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
|
|
|
|
|
2017-05-21 10:57:32 +03:00
|
|
|
def topicmatch(ui, commands, 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))
|
|
|
|
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
|
2017-06-01 16:24:15 +03:00
|
|
|
docs = _(pycompat.getdoc(entry[0])) 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-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]))
|
2017-08-05 17:15:37 +03:00
|
|
|
try:
|
|
|
|
mod = extensions.load(ui, name, '')
|
|
|
|
except ImportError:
|
|
|
|
# debug message would be printed in extensions.load()
|
|
|
|
continue
|
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('^')
|
2017-06-01 16:24:15 +03:00
|
|
|
cmddoc = pycompat.getdoc(entry[0])
|
|
|
|
if cmddoc:
|
|
|
|
cmddoc = gettext(cmddoc).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')),
|
2017-11-01 21:24:08 +03:00
|
|
|
(['config'], _('Config Registrar'),
|
2017-10-27 19:19:07 +03:00
|
|
|
loaddoc('config', 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')),
|
2017-10-31 06:35:30 +03:00
|
|
|
(["flags"], _("Command-line flags"), loaddoc('flags')),
|
2009-10-04 11:59:13 +04:00
|
|
|
(["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):
|
2017-06-01 16:24:15 +03:00
|
|
|
text = (pycompat.getdoc(items[name]) 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:
|
2017-05-28 22:51:07 +03:00
|
|
|
# Abuse latin1 to use textwrap.dedent() on bytes.
|
|
|
|
text = textwrap.dedent(text.decode('latin1')).encode('latin1')
|
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
|
|
|
|
2018-05-03 14:33:07 +03:00
|
|
|
def makesubcmdlist(cmd, subcommands, verbose, quiet):
|
|
|
|
cmdhelp = []
|
|
|
|
for name, entry in subcommands.items():
|
|
|
|
aliases = cmdutil.parsealiases(name)
|
|
|
|
name = ', '.join(aliases) if verbose else aliases[0]
|
|
|
|
doc = pycompat.getdoc(entry[0]) or ''
|
|
|
|
doc, __, rest = doc.strip().partition('\n')
|
|
|
|
if verbose and rest.strip():
|
|
|
|
if len(entry) > 2: # synopsis
|
|
|
|
name = '{} {}'.format(name, entry[2])
|
|
|
|
cmdhelp.append(" :%s: %s\n" % (name, doc))
|
|
|
|
rst = ['\n%s:\n\n' % _('subcommands')]
|
|
|
|
rst.extend(sorted(cmdhelp))
|
|
|
|
if not quiet:
|
|
|
|
rst.append(_("\n(use 'hg help %s [subcommand]' "
|
|
|
|
"to show complete subcommand help)\n") % cmd)
|
|
|
|
return rst
|
|
|
|
|
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
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
class _helpdispatch(object):
|
|
|
|
def __init__(
|
|
|
|
self, ui, commands, unknowncmd=False, full=False, subtopic=None,
|
|
|
|
**opts):
|
|
|
|
self.ui = ui
|
|
|
|
self.commands = commands
|
|
|
|
self.subtopic = subtopic
|
|
|
|
self.unknowncmd = unknowncmd
|
|
|
|
self.full = full
|
|
|
|
self.opts = opts
|
|
|
|
|
|
|
|
def dispatch(self, name):
|
|
|
|
queries = []
|
|
|
|
if self.unknowncmd:
|
|
|
|
queries += [self.helpextcmd]
|
|
|
|
if self.opts.get('extension'):
|
|
|
|
queries += [self.helpext]
|
|
|
|
if self.opts.get('command'):
|
|
|
|
queries += [self.helpcmd]
|
|
|
|
if not queries:
|
|
|
|
queries = (self.helptopic, self.helpcmd, self.helpext,
|
|
|
|
self.helpextcmd)
|
|
|
|
for f in queries:
|
|
|
|
try:
|
|
|
|
return f(name, self.subtopic)
|
|
|
|
except error.UnknownCommand:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if self.unknowncmd:
|
|
|
|
raise error.UnknownCommand(name)
|
|
|
|
else:
|
|
|
|
msg = _('no such help topic: %s') % name
|
|
|
|
hint = _("try 'hg help --keyword %s'") % name
|
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def helpcmd(self, name, subtopic=None):
|
2013-02-10 01:51:21 +04:00
|
|
|
try:
|
2018-05-03 14:33:07 +03:00
|
|
|
cmd, args, aliases, entry = (
|
|
|
|
cmdutil.findsubcmd(name.split(), self.commands.table,
|
|
|
|
strict=self.unknowncmd, partial=True))
|
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)
|
2018-03-26 18:44:39 +03:00
|
|
|
rst = self.helplist(name, select)
|
2013-02-10 01:51:21 +04:00
|
|
|
return rst
|
2018-05-03 14:33:07 +03:00
|
|
|
except error.UnknownSubcommand as inst:
|
|
|
|
cmd, subcmd, __ = inst
|
|
|
|
msg = _("'%s' has no such subcommand: %s") % (cmd, subcmd)
|
|
|
|
hint = _("run 'hg help %s' to see available subcommands") % cmd
|
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
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:
|
2018-03-26 18:44:39 +03:00
|
|
|
rst.extend(self.helpextcmd(entry[0].cmdname))
|
2014-08-13 14:38:47 +04:00
|
|
|
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:
|
2018-05-03 14:33:07 +03:00
|
|
|
rst.append('hg %s %s\n' % (cmd, entry[2]))
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
2018-05-03 14:33:07 +03:00
|
|
|
rst.append('hg %s\n' % cmd)
|
2013-02-10 01:51:21 +04:00
|
|
|
# aliases
|
2018-03-26 18:44:39 +03:00
|
|
|
if self.full and not self.ui.quiet and len(aliases) > 1:
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:]))
|
|
|
|
rst.append('\n')
|
|
|
|
|
|
|
|
# description
|
2017-06-01 16:24:15 +03:00
|
|
|
doc = gettext(pycompat.getdoc(entry[0]))
|
2013-02-10 01:51:21 +04:00
|
|
|
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)
|
2018-03-26 18:44:39 +03:00
|
|
|
if self.ui.quiet or not self.full:
|
2013-02-10 01:51:21 +04:00
|
|
|
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)
|
2017-06-01 16:24:15 +03:00
|
|
|
doc = gettext(pycompat.getdoc(mod)) or ''
|
2013-02-10 01:51:21 +04:00
|
|
|
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
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.ui.quiet and entry[1]:
|
|
|
|
rst.append(optrst(_("options"), entry[1], self.ui.verbose))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if self.ui.verbose:
|
2014-08-12 12:53:33 +04:00
|
|
|
rst.append(optrst(_("global options"),
|
2018-03-26 18:44:39 +03:00
|
|
|
self.commands.globalopts, self.ui.verbose))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2018-05-03 14:33:07 +03:00
|
|
|
# subcommands
|
|
|
|
if entry[0].subcommands:
|
|
|
|
rst.extend(makesubcmdlist(cmd, entry[0].subcommands,
|
|
|
|
self.ui.verbose, self.ui.quiet))
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.ui.verbose:
|
|
|
|
if not self.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)
|
2018-03-26 18:44:39 +03:00
|
|
|
elif not self.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
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def helplist(self, name, 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 = {}
|
2018-03-26 18:44:39 +03:00
|
|
|
for c, e in self.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
|
2018-03-26 18:44:39 +03:00
|
|
|
e[0].__module__ != self.commands.__name__):
|
2013-02-10 01:51:21 +04:00
|
|
|
continue
|
|
|
|
if name == "shortlist" and not f.startswith("^"):
|
|
|
|
continue
|
|
|
|
f = f.lstrip("^")
|
2017-06-01 16:24:15 +03:00
|
|
|
doc = pycompat.getdoc(e[0])
|
2018-03-26 18:44:39 +03:00
|
|
|
if filtercmd(self.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:
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.ui.quiet:
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.append(_('no commands defined\n'))
|
|
|
|
return rst
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.ui.quiet:
|
2013-02-10 01:51:21 +04:00
|
|
|
rst.append(header)
|
|
|
|
fns = sorted(h)
|
|
|
|
for f in fns:
|
2018-03-26 18:44:39 +03:00
|
|
|
if self.ui.verbose:
|
2013-02-10 01:51:21 +04:00
|
|
|
commacmds = cmds[f].replace("|",", ")
|
|
|
|
rst.append(" :%s: %s\n" % (commacmds, h[f]))
|
|
|
|
else:
|
|
|
|
rst.append(' :%s: %s\n' % (f, h[f]))
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
ex = self.opts.get
|
2017-12-10 02:16:39 +03:00
|
|
|
anyopts = (ex(r'keyword') or not (ex(r'command') or ex(r'extension')))
|
2015-12-09 08:56:54 +03:00
|
|
|
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))
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if self.ui.quiet:
|
2014-08-12 12:42:09 +04:00
|
|
|
pass
|
2018-03-26 18:44:39 +03:00
|
|
|
elif self.ui.verbose:
|
|
|
|
rst.append('\n%s\n' % optrst(
|
|
|
|
_("global options"), self.commands.globalopts, self.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"))
|
2018-03-26 18:44:39 +03:00
|
|
|
elif name and not self.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
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def helptopic(self, 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):
|
2018-03-26 18:44:39 +03:00
|
|
|
rst += [" %s\n" % l for l in doc(self.ui).splitlines()]
|
2013-02-10 01:51:21 +04:00
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.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:
|
2018-03-26 18:44:39 +03:00
|
|
|
cmdutil.findcmd(name, self.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
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def helpext(self, name, subtopic=None):
|
2013-02-10 01:51:21 +04:00
|
|
|
try:
|
|
|
|
mod = extensions.find(name)
|
2017-06-01 16:24:15 +03:00
|
|
|
doc = gettext(pycompat.getdoc(mod)) or _('no help text available')
|
2013-02-10 01:51:21 +04:00
|
|
|
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')
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
if not self.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])
|
2018-03-26 18:44:39 +03:00
|
|
|
rst.extend(self.helplist(name, modcmds.__contains__))
|
2013-02-10 01:51:21 +04:00
|
|
|
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
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def helpextcmd(self, name, subtopic=None):
|
|
|
|
cmd, ext, mod = extensions.disabledcmd(
|
|
|
|
self.ui, name, self.ui.configbool('ui', 'strict'))
|
2018-02-07 05:10:48 +03:00
|
|
|
doc = gettext(pycompat.getdoc(mod))
|
|
|
|
if doc is None:
|
|
|
|
doc = _('(no help text available)')
|
|
|
|
else:
|
|
|
|
doc = doc.splitlines()[0]
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-03-26 18:44:39 +03:00
|
|
|
def help_(ui, commands, name, unknowncmd=False, full=True, subtopic=None,
|
|
|
|
**opts):
|
|
|
|
'''
|
|
|
|
Generate the help for 'name' as unformatted restructured text. If
|
|
|
|
'name' is None, describe the commands available.
|
|
|
|
'''
|
|
|
|
|
|
|
|
opts = pycompat.byteskwargs(opts)
|
|
|
|
dispatch = _helpdispatch(ui, commands, unknowncmd, full, subtopic, **opts)
|
|
|
|
|
2013-02-10 01:51:21 +04:00
|
|
|
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):
|
2017-05-21 10:57:32 +03:00
|
|
|
matches = topicmatch(ui, commands, 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':
|
2018-03-26 18:44:39 +03:00
|
|
|
rst = dispatch.dispatch(name)
|
2013-02-10 01:51:21 +04:00
|
|
|
else:
|
|
|
|
# program name
|
|
|
|
if not ui.quiet:
|
|
|
|
rst = [_("Mercurial Distributed SCM\n"), '\n']
|
2018-03-26 18:44:39 +03:00
|
|
|
rst.extend(dispatch.helplist(name, None, **pycompat.strkwargs(opts)))
|
2013-02-10 01:51:21 +04:00
|
|
|
|
|
|
|
return ''.join(rst)
|
2017-02-21 22:17:31 +03:00
|
|
|
|
2017-05-21 10:57:32 +03:00
|
|
|
def formattedhelp(ui, commands, name, keep=None, unknowncmd=False, full=True,
|
|
|
|
**opts):
|
2017-02-21 22:17:31 +03:00
|
|
|
"""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
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
textwidth = ui.configint('ui', 'textwidth')
|
2017-02-21 22:17:31 +03:00
|
|
|
termwidth = ui.termwidth() - 2
|
|
|
|
if textwidth <= 0 or termwidth < textwidth:
|
|
|
|
textwidth = termwidth
|
2017-05-21 10:57:32 +03:00
|
|
|
text = help_(ui, commands, name,
|
2017-02-21 22:17:31 +03:00
|
|
|
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
|