##// END OF EJS Templates
auto-upgrade: add a test case with no permission to lock the repository...
auto-upgrade: add a test case with no permission to lock the repository This show the current behavior when the repository is unlockable. The current behavior is to abort, which is probably not great. Now that we have a proper test, we can think about the behavior we want in a later changeset. Differential Revision: https://phab.mercurial-scm.org/D12615

File last commit:

r49888:7bd5f862 default
r50091:1c233af9 default
Show More
help.py
1180 lines | 36.6 KiB | text/x-python | PythonLexer
Matt Mackall
Add basic support for help topics and a dates topic
r3795 # help.py - help data for mercurial
#
Raphaël Gomès
contributor: change mentions of mpm to olivia...
r47575 # Copyright 2006 Olivia Mackall <olivia@selenic.com>
Matt Mackall
Add basic support for help topics and a dates topic
r3795 #
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Matt Mackall
Add basic support for help topics and a dates topic
r3795
Gregory Szorc
help: use absolute_import
r27479
import itertools
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 import re
Gregory Szorc
help: use absolute_import
r27479 import textwrap
from .i18n import (
_,
gettext,
)
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import getattr
Gregory Szorc
help: use absolute_import
r27479 from . import (
cmdutil,
encoding,
error,
extensions,
Daniel Ploch
fancyopts: fix rendering of customopt defaults in help text...
r37109 fancyopts,
Gregory Szorc
help: use absolute_import
r27479 filemerge,
fileset,
minirst,
Pulkit Goyal
py3: make sure opts are passed and used correctly in help command...
r32143 pycompat,
rdamazio@google.com
help: adding support for command categories...
r40327 registrar,
Gregory Szorc
help: use absolute_import
r27479 revset,
templatefilters,
Yuya Nishihara
templater: split template functions to new module...
r36940 templatefuncs,
Gregory Szorc
help: use absolute_import
r27479 templatekw,
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 ui as uimod,
Gregory Szorc
help: use absolute_import
r27479 util,
)
Augie Fackler
formatting: blacken the codebase...
r43346 from .hgweb import webcommands
Martin von Zweigbergk
util: remove datapath and swith users over to resourceutil...
r44070 from .utils import (
compression,
resourceutil,
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 stringutil,
Martin von Zweigbergk
util: remove datapath and swith users over to resourceutil...
r44070 )
Cédric Duval
help: adding a new help topic about extensions...
r8863
Martin von Zweigbergk
cleanup: use set literals...
r32291 _exclkeywords = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"(ADVANCED)",
b"(DEPRECATED)",
b"(EXPERIMENTAL)",
Jun Wu
help: hide command line options marked as "advanced"...
r31080 # i18n: "(ADVANCED)" is a keyword, must be translated consistently
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"(ADVANCED)"),
Yuya Nishihara
help: include parens in DEPRECATED/EXPERIMENTAL keywords...
r26370 # i18n: "(DEPRECATED)" is a keyword, must be translated consistently
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"(DEPRECATED)"),
Yuya Nishihara
help: include parens in DEPRECATED/EXPERIMENTAL keywords...
r26370 # i18n: "(EXPERIMENTAL)" is a keyword, must be translated consistently
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"(EXPERIMENTAL)"),
Martin von Zweigbergk
cleanup: use set literals...
r32291 }
Yuya Nishihara
help: define list of keywords that should be excluded from non-verbose output...
r26369
rdamazio@google.com
help: adding support for command categories...
r40327 # The order in which command categories will be displayed.
# Extensions with custom categories should insert them into this list
# after/before the appropriate item, rather than replacing the list or
# assuming absolute positions.
CATEGORY_ORDER = [
rdamazio@google.com
help: assigning categories to existing commands...
r40329 registrar.command.CATEGORY_REPO_CREATION,
registrar.command.CATEGORY_REMOTE_REPO_MANAGEMENT,
registrar.command.CATEGORY_COMMITTING,
registrar.command.CATEGORY_CHANGE_MANAGEMENT,
registrar.command.CATEGORY_CHANGE_ORGANIZATION,
registrar.command.CATEGORY_FILE_CONTENTS,
Augie Fackler
formatting: blacken the codebase...
r43346 registrar.command.CATEGORY_CHANGE_NAVIGATION,
rdamazio@google.com
help: assigning categories to existing commands...
r40329 registrar.command.CATEGORY_WORKING_DIRECTORY,
registrar.command.CATEGORY_IMPORT_EXPORT,
registrar.command.CATEGORY_MAINTENANCE,
registrar.command.CATEGORY_HELP,
registrar.command.CATEGORY_MISC,
rdamazio@google.com
help: adding support for command categories...
r40327 registrar.command.CATEGORY_NONE,
]
# Human-readable category names. These are translated.
# Extensions with custom categories should add their names here.
CATEGORY_NAMES = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 registrar.command.CATEGORY_REPO_CREATION: b'Repository creation',
registrar.command.CATEGORY_REMOTE_REPO_MANAGEMENT: b'Remote repository management',
registrar.command.CATEGORY_COMMITTING: b'Change creation',
registrar.command.CATEGORY_CHANGE_NAVIGATION: b'Change navigation',
registrar.command.CATEGORY_CHANGE_MANAGEMENT: b'Change manipulation',
registrar.command.CATEGORY_CHANGE_ORGANIZATION: b'Change organization',
registrar.command.CATEGORY_WORKING_DIRECTORY: b'Working directory management',
registrar.command.CATEGORY_FILE_CONTENTS: b'File content management',
registrar.command.CATEGORY_IMPORT_EXPORT: b'Change import/export',
registrar.command.CATEGORY_MAINTENANCE: b'Repository maintenance',
registrar.command.CATEGORY_HELP: b'Help',
registrar.command.CATEGORY_MISC: b'Miscellaneous commands',
registrar.command.CATEGORY_NONE: b'Uncategorized commands',
rdamazio@google.com
help: adding support for command categories...
r40327 }
Rodrigo Damazio
help: splitting the topics by category...
r40328 # Topic categories.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 TOPIC_CATEGORY_IDS = b'ids'
TOPIC_CATEGORY_OUTPUT = b'output'
TOPIC_CATEGORY_CONFIG = b'config'
TOPIC_CATEGORY_CONCEPTS = b'concepts'
TOPIC_CATEGORY_MISC = b'misc'
TOPIC_CATEGORY_NONE = b'none'
Rodrigo Damazio
help: splitting the topics by category...
r40328
# The order in which topic categories will be displayed.
# Extensions with custom categories should insert them into this list
# after/before the appropriate item, rather than replacing the list or
# assuming absolute positions.
TOPIC_CATEGORY_ORDER = [
Rodrigo Damazio
help: assigning topic categories...
r40330 TOPIC_CATEGORY_IDS,
TOPIC_CATEGORY_OUTPUT,
TOPIC_CATEGORY_CONFIG,
TOPIC_CATEGORY_CONCEPTS,
TOPIC_CATEGORY_MISC,
Rodrigo Damazio
help: splitting the topics by category...
r40328 TOPIC_CATEGORY_NONE,
]
# Human-readable topic category names. These are translated.
TOPIC_CATEGORY_NAMES = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 TOPIC_CATEGORY_IDS: b'Mercurial identifiers',
TOPIC_CATEGORY_OUTPUT: b'Mercurial output',
TOPIC_CATEGORY_CONFIG: b'Mercurial configuration',
TOPIC_CATEGORY_CONCEPTS: b'Concepts',
TOPIC_CATEGORY_MISC: b'Miscellaneous',
TOPIC_CATEGORY_NONE: b'Uncategorized topics',
Rodrigo Damazio
help: splitting the topics by category...
r40328 }
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
help: exclude deprecated extensions in the disabled part of 'help extensions'
r20582 def listexts(header, exts, indent=1, showdeprecated=False):
Cédric Duval
help: more improvements for the extensions topic...
r8879 '''return a text listing of the given extensions'''
Olav Reinert
help: format extension lists using RST...
r16852 rst = []
if exts:
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for name, desc in sorted(exts.items()):
Yuya Nishihara
help: unify handling of DEPRECATED/EXPERIMENTAL keywords...
r26371 if not showdeprecated and any(w in desc for w in _exclkeywords):
Augie Fackler
help: exclude deprecated extensions in the disabled part of 'help extensions'
r20582 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'%s:%s: %s\n' % (b' ' * indent, name, desc))
timeless
help: make listexts less confusing for deprecated exts...
r27151 if rst:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.insert(0, b'\n%s\n\n' % header)
Olav Reinert
help: format extension lists using RST...
r16852 return rst
Cédric Duval
help: refactor extensions listing, and show enabled ones in the dedicated topic
r8864
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
help: pass around ui to doc loader (API)...
r26413 def extshelp(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst = loaddoc(b'extensions')(ui).splitlines(True)
Augie Fackler
formatting: blacken the codebase...
r43346 rst.extend(
listexts(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'enabled extensions:'), extensions.enabled(), showdeprecated=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
rst.extend(
listexts(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'disabled extensions:'),
Augie Fackler
formatting: blacken the codebase...
r43346 extensions.disabled(),
showdeprecated=ui.verbose,
)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doc = b''.join(rst)
Cédric Duval
help: adding a new help topic about extensions...
r8863 return doc
Martin Geisler
i18n: mark help strings for translation...
r7013
Augie Fackler
cleanup: re-run black on the codebase...
r44787
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 def parsedefaultmarker(text):
"""given a text 'abc (DEFAULT: def.ghi)',
returns (b'abc', (b'def', b'ghi')). Otherwise return None"""
if text[-1:] == b')':
marker = b' (DEFAULT: '
pos = text.find(marker)
if pos >= 0:
Augie Fackler
cleanup: re-run black on the codebase...
r44787 item = text[pos + len(marker) : -1]
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 return text[:pos], item.split(b'.', 2)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
cleanup: re-run black on the codebase...
r44787
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 def optrst(header, options, verbose, ui):
Olav Reinert
help: move some helper functions to help.py
r16781 data = []
multioccur = False
for option in options:
if len(option) == 5:
shortopt, longopt, default, desc, optlabel = option
else:
shortopt, longopt, default, desc = option
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 optlabel = _(b"VALUE") # default label
Olav Reinert
help: move some helper functions to help.py
r16781
Yuya Nishihara
help: define list of keywords that should be excluded from non-verbose output...
r26369 if not verbose and any(w in desc for w in _exclkeywords):
Olav Reinert
help: move some helper functions to help.py
r16781 continue
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 defaultstrsuffix = b''
if default is None:
parseresult = parsedefaultmarker(desc)
if parseresult is not None:
(desc, (section, name)) = parseresult
if ui.configbool(section, name):
default = True
defaultstrsuffix = _(b' from config')
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 so = b''
Olav Reinert
help: move some helper functions to help.py
r16781 if shortopt:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 so = b'-' + shortopt
lo = b'--' + longopt
Martin von Zweigbergk
help: show "[no-]" only for default-on Flags...
r41045 if default is True:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lo = b'--[no-]' + longopt
Daniel Ploch
fancyopts: fix rendering of customopt defaults in help text...
r37109
if isinstance(default, fancyopts.customopt):
Daniel Ploch
fancyopts: prevent mutation of the default value in customopts...
r37110 default = default.getdefaultvalue()
Martin von Zweigbergk
help: hide default value for default-off flags...
r41046 if default and not callable(default):
Augie Fackler
help: convert flag default to bytes portably...
r32619 # 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.
Martin von Zweigbergk
help: use "default: on" instead of "default: True"...
r40989 defaultstr = pycompat.bytestr(default)
Martin von Zweigbergk
help: hide default value for default-off flags...
r41046 if default is True:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 defaultstr = _(b"on")
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 desc += _(b" (default: %s)") % (defaultstr + defaultstrsuffix)
Olav Reinert
help: move some helper functions to help.py
r16781
if isinstance(default, list):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lo += b" %s [+]" % optlabel
Olav Reinert
help: move some helper functions to help.py
r16781 multioccur = True
elif (default is not None) and not isinstance(default, bool):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lo += b" %s" % optlabel
Olav Reinert
help: move some helper functions to help.py
r16781
data.append((so, lo, desc))
Matt Mackall
help: fold repeatable option message into option table header...
r22117 if multioccur:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 header += _(b" ([+] can be repeated)")
Olav Reinert
help: move some helper functions to help.py
r16781
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst = [b'\n%s:\n\n' % header]
Matt Mackall
help: roll option list header into option formatter
r22116 rst.extend(minirst.maketable(data, 1))
Olav Reinert
help: move some helper functions to help.py
r16781
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(rst)
Olav Reinert
help: move some helper functions to help.py
r16781
Augie Fackler
formatting: blacken the codebase...
r43346
FUJIWARA Katsunori
help: indicate help omitting if help document is not fully displayed...
r17837 def indicateomitted(rst, omitted, notomitted=None):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n\n.. container:: omitted\n\n %s\n\n' % omitted)
FUJIWARA Katsunori
help: indicate help omitting if help document is not fully displayed...
r17837 if notomitted:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n\n.. container:: notomitted\n\n %s\n\n' % notomitted)
FUJIWARA Katsunori
help: indicate help omitting if help document is not fully displayed...
r17837
Augie Fackler
formatting: blacken the codebase...
r43346
rdamazio@google.com
help: displaying documented aliases by default...
r40450 def filtercmd(ui, cmd, func, kw, doc):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not ui.debugflag and cmd.startswith(b"debug") and kw != b"debug":
rdamazio@google.com
help: displaying documented aliases by default...
r40450 # Debug command, and user is not looking for those.
timeless
help: refactor filtercmd
r27323 return True
rdamazio@google.com
help: displaying documented aliases by default...
r40450 if not ui.verbose:
if not kw and not doc:
# Command had no documentation, no point in showing it by default.
return True
if getattr(func, 'alias', False) and not getattr(func, 'owndoc', False):
# Alias didn't have its own documentation.
return True
if doc and any(w in doc for w in _exclkeywords):
# Documentation has excluded keywords.
return True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if kw == b"shortlist" and not getattr(func, 'helpbasic', False):
rdamazio@google.com
help: displaying documented aliases by default...
r40450 # We're presenting the short list but the command is not basic.
timeless
help: refactor filtercmd
r27323 return True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.configbool(b'help', b'hidden-command.%s' % cmd):
rdamazio@google.com
help: displaying documented aliases by default...
r40450 # Configuration explicitly hides the command.
timeless
help: refactor filtercmd
r27323 return True
return False
Augie Fackler
formatting: blacken the codebase...
r43346
rdamazio@google.com
help: allow hiding of help topics...
r40449 def filtertopic(ui, topic):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return ui.configbool(b'help', b'hidden-topic.%s' % topic, False)
rdamazio@google.com
help: allow hiding of help topics...
r40449
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
help: pass commands module by argument...
r32567 def topicmatch(ui, commands, kw):
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 """Return help topics matching kw.
Returns {'section': [(name, summary), ...], ...} where section is
one of topics, commands, extensions, or extensioncommands.
"""
kw = encoding.lower(kw)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 def lowercontains(container):
Nikolaj Sjujskij
help: fix search with `-k` option in non-ASCII locales...
r16845 return kw in encoding.lower(container) # translated in helptable
Augie Fackler
formatting: blacken the codebase...
r43346
results = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'topics': [],
b'commands': [],
b'extensions': [],
b'extensioncommands': [],
Augie Fackler
formatting: blacken the codebase...
r43346 }
Rodrigo Damazio
help: splitting the topics by category...
r40328 for topic in helptable:
names, header, doc = topic[0:3]
Gregory Szorc
help: only call doc() when it is callable...
r22322 # Old extensions may use a str as doc.
Augie Fackler
formatting: blacken the codebase...
r43346 if (
sum(map(lowercontains, names))
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 or lowercontains(header)
Augie Fackler
formatting: blacken the codebase...
r43346 or (callable(doc) and lowercontains(doc(ui)))
):
rdamazio@google.com
help: allow hiding of help topics...
r40449 name = names[0]
if not filtertopic(ui, name):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 results[b'topics'].append((names[0], header))
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for cmd, entry in commands.table.items():
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 if len(entry) == 3:
summary = entry[2]
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 summary = b''
Nikolaj Sjujskij
help: fix search with `-k` option in non-ASCII locales...
r16845 # translate docs *before* searching there
rdamazio@google.com
help: displaying documented aliases by default...
r40450 func = entry[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 docs = _(pycompat.getdoc(func)) or b''
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 if kw in cmd or lowercontains(summary) or lowercontains(docs):
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 if docs:
summary = stringutil.firstline(docs)
Yuya Nishihara
help: use cmdutil.parsealiases() to resolve command name...
r36264 cmdname = cmdutil.parsealiases(cmd)[0]
rdamazio@google.com
help: displaying documented aliases by default...
r40450 if filtercmd(ui, cmdname, func, kw, docs):
timeless
help: call filtercmd from topicmatch...
r27324 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 results[b'commands'].append((cmdname, summary))
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 for name, docs in itertools.chain(
Gregory Szorc
help: remove pycompat.iteritems()...
r49778 extensions.enabled(False).items(),
extensions.disabled().items(),
Augie Fackler
formatting: blacken the codebase...
r43346 ):
Simon Farnsworth
help: don't crash in keyword search if an extension fails to provide docs...
r28058 if not docs:
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 name = name.rpartition(b'.')[-1]
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 if lowercontains(name) or lowercontains(docs):
Nikolaj Sjujskij
help: fix search with `-k` option in non-ASCII locales...
r16845 # extension docs are already translated
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 results[b'extensions'].append((name, stringutil.firstline(docs)))
Yuya Nishihara
help: do not abort topicmatch() because of unimportable extensions...
r34913 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mod = extensions.load(ui, name, b'')
Yuya Nishihara
help: do not abort topicmatch() because of unimportable extensions...
r34913 except ImportError:
# debug message would be printed in extensions.load()
continue
Gregory Szorc
help: remove pycompat.iteritems()...
r49778 for cmd, entry in getattr(mod, 'cmdtable', {}).items():
Augie Fackler
help: add --keyword (-k) for searching help
r16711 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
Yuya Nishihara
help: use cmdutil.parsealiases() to resolve command name...
r36264 cmdname = cmdutil.parsealiases(cmd)[0]
rdamazio@google.com
help: displaying documented aliases by default...
r40450 func = entry[0]
cmddoc = pycompat.getdoc(func)
Yuya Nishihara
py3: convert __doc__ back to bytes in help.py...
r32615 if cmddoc:
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 cmddoc = stringutil.firstline(gettext(cmddoc))
Thomas Arendsen Hein
help: fix 'hg help -k' matching an extension without docs...
r16884 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmddoc = _(b'(no help text available)')
rdamazio@google.com
help: displaying documented aliases by default...
r40450 if filtercmd(ui, cmdname, func, kw, cmddoc):
timeless
help: filter extension commands
r27387 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 results[b'extensioncommands'].append((cmdname, cmddoc))
Augie Fackler
help: introduce topicmatch for finding topics matching a keyword
r16710 return results
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
help: teach loaddoc to load from a different directory...
r27375 def loaddoc(topic, subdir=None):
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 """Return a delayed loader for help/topic.txt."""
Matt Mackall
move environment topic
r3798
Yuya Nishihara
help: pass around ui to doc loader (API)...
r26413 def loader(ui):
Matt Harbison
resourceutil: don't limit resources to the `mercurial` package...
r44479 package = b'mercurial.helptext'
Gregory Szorc
help: teach loaddoc to load from a different directory...
r27375 if subdir:
Matt Harbison
resourceutil: don't limit resources to the `mercurial` package...
r44479 package += b'.' + subdir
Martin von Zweigbergk
help: get helptext/ data from `resources` module if available...
r44323 with resourceutil.open_resource(package, topic + b'.txt') as fp:
doc = gettext(fp.read())
Patrick Mezard
help: add topic rewriting hooks...
r12820 for rewriter in helphooks.get(topic, []):
Yuya Nishihara
help: pass around ui to rewriter hooks (API)...
r26414 doc = rewriter(ui, topic, doc)
Patrick Mezard
help: add topic rewriting hooks...
r12820 return doc
Martin Geisler
help: move help topics from mercurial/help.py to help/*.txt...
r9539 return loader
Alexander Solovyov
help: add a topic about some of the templating features
r7677
Augie Fackler
formatting: blacken the codebase...
r43346
internalstable = sorted(
[
documentation: add some internals documentation about bid merge...
r45619 (
[b'bid-merge'],
_(b'Bid Merge Algorithm'),
loaddoc(b'bid-merge', subdir=b'internals'),
),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ([b'bundle2'], _(b'Bundle2'), loaddoc(b'bundle2', subdir=b'internals')),
([b'bundles'], _(b'Bundles'), loaddoc(b'bundles', subdir=b'internals')),
([b'cbor'], _(b'CBOR'), loaddoc(b'cbor', subdir=b'internals')),
([b'censor'], _(b'Censor'), loaddoc(b'censor', subdir=b'internals')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'changegroups'],
_(b'Changegroups'),
loaddoc(b'changegroups', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'config'],
_(b'Config Registrar'),
loaddoc(b'config', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Simon Sapin
dirstate-v2: Add internal documentation...
r48978 [b'dirstate-v2'],
_(b'dirstate-v2 file format'),
loaddoc(b'dirstate-v2', subdir=b'internals'),
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'extensions', b'extension'],
_(b'Extension API'),
loaddoc(b'extensions', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'mergestate'],
_(b'Mergestate'),
loaddoc(b'mergestate', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'requirements'],
_(b'Repository Requirements'),
loaddoc(b'requirements', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'revlogs'],
_(b'Revision Logs'),
loaddoc(b'revlogs', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'wireprotocol'],
_(b'Wire Protocol'),
loaddoc(b'wireprotocol', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'wireprotocolrpc'],
_(b'Wire Protocol RPC'),
loaddoc(b'wireprotocolrpc', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'wireprotocolv2'],
_(b'Wire Protocol Version 2'),
loaddoc(b'wireprotocolv2', subdir=b'internals'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
]
)
Gregory Szorc
help: add "internals" topic...
r27376
def internalshelp(ui):
"""Generate the index for the "internals" topic."""
Augie Fackler
formatting: blacken the codebase...
r43346 lines = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'To access a subtopic, use "hg help internals.{subtopic-name}"\n',
b'\n',
Augie Fackler
formatting: blacken the codebase...
r43346 ]
Gregory Szorc
help: add "internals" topic...
r27376 for names, header, doc in internalstable:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lines.append(b' :%s: %s\n' % (names[0], header))
Gregory Szorc
help: add "internals" topic...
r27376
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(lines)
Gregory Szorc
help: add "internals" topic...
r27376
Augie Fackler
formatting: blacken the codebase...
r43346
helptable = sorted(
[
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'bundlespec'],
_(b"Bundle File Formats"),
loaddoc(b'bundlespec'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONCEPTS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'color'],
_(b"Colorizing Outputs"),
loaddoc(b'color'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_OUTPUT,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"config", b"hgrc"],
_(b"Configuration Files"),
loaddoc(b'config'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'deprecated'],
_(b"Deprecated Features"),
loaddoc(b'deprecated'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_MISC,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"dates"],
_(b"Date Formats"),
loaddoc(b'dates'),
TOPIC_CATEGORY_OUTPUT,
),
(
[b"flags"],
_(b"Command-line flags"),
loaddoc(b'flags'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"patterns"],
_(b"File Name Patterns"),
loaddoc(b'patterns'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_IDS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'environment', b'env'],
_(b'Environment Variables'),
loaddoc(b'environment'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [
b'revisions',
b'revs',
b'revsets',
b'revset',
b'multirevs',
b'mrevs',
],
_(b'Specifying Revisions'),
loaddoc(b'revisions'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_IDS,
),
(
Raphaël Gomès
docs: add documentation about Rust...
r49364 [
b'rust',
b'rustext',
],
_(b'Rust in Mercurial'),
loaddoc(b'rust'),
TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'filesets', b'fileset'],
_(b"Specifying File Sets"),
loaddoc(b'filesets'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_IDS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'diffs'],
_(b'Diff Formats'),
loaddoc(b'diffs'),
TOPIC_CATEGORY_OUTPUT,
),
(
[b'merge-tools', b'mergetools', b'mergetool'],
_(b'Merge Tools'),
loaddoc(b'merge-tools'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'templating', b'templates', b'template', b'style'],
_(b'Template Usage'),
loaddoc(b'templates'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_OUTPUT,
),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ([b'urls'], _(b'URL Paths'), loaddoc(b'urls'), TOPIC_CATEGORY_IDS),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"extensions"],
_(b"Using Additional Features"),
Augie Fackler
formatting: blacken the codebase...
r43346 extshelp,
TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"subrepos", b"subrepo"],
_(b"Subrepositories"),
loaddoc(b'subrepos'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONCEPTS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"hgweb"],
_(b"Configuring hgweb"),
loaddoc(b'hgweb'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"glossary"],
_(b"Glossary"),
loaddoc(b'glossary'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONCEPTS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"hgignore", b"ignore"],
_(b"Syntax for Mercurial Ignore Files"),
loaddoc(b'hgignore'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_IDS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b"phases"],
_(b"Working with Phases"),
loaddoc(b'phases'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONCEPTS,
),
(
Martin von Zweigbergk
help: add topic about evolution, based on text from evolve extension...
r47781 [b"evolution"],
_(b"Safely rewriting history (EXPERIMENTAL)"),
loaddoc(b'evolution'),
TOPIC_CATEGORY_CONCEPTS,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'scripting'],
_(b'Using Mercurial from scripts and automation'),
loaddoc(b'scripting'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_MISC,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'internals'],
_(b"Technical implementation topics"),
Augie Fackler
formatting: blacken the codebase...
r43346 internalshelp,
TOPIC_CATEGORY_MISC,
),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [b'pager'],
_(b"Pager Support"),
loaddoc(b'pager'),
Augie Fackler
formatting: blacken the codebase...
r43346 TOPIC_CATEGORY_CONFIG,
),
]
)
Patrick Mezard
help: add topic rewriting hooks...
r12820
Gregory Szorc
help: support loading sub-topics...
r27379 # Maps topics with sub-topics to a list of their sub-topics.
subtopics = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'internals': internalstable,
Gregory Szorc
help: support loading sub-topics...
r27379 }
Patrick Mezard
help: add topic rewriting hooks...
r12820 # Map topics to lists of callable taking the current topic help and
# returning the updated version
Matt Mackall
help: consolidate topic hooks in help.py...
r14318 helphooks = {}
Patrick Mezard
help: add topic rewriting hooks...
r12820
Augie Fackler
formatting: blacken the codebase...
r43346
Patrick Mezard
help: add topic rewriting hooks...
r12820 def addtopichook(topic, rewriter):
helphooks.setdefault(topic, []).append(rewriter)
Patrick Mezard
help: extract items doc generation function
r13593
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
help: pass around ui to rewriter hooks (API)...
r26414 def makeitemsdoc(ui, topic, doc, marker, items, dedent=False):
Patrick Mezard
help: extract items doc generation function
r13593 """Extract docstring from the items key to function mapping, build a
timeless@mozdev.org
help: fix makeitemsdoc English description
r26196 single documentation block and use it to overwrite the marker in doc.
Patrick Mezard
help: extract items doc generation function
r13593 """
entries = []
for name in sorted(items):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 text = (pycompat.getdoc(items[name]) or b'').rstrip()
Augie Fackler
formatting: blacken the codebase...
r43346 if not text or not ui.verbose and any(w in text for w in _exclkeywords):
Patrick Mezard
help: extract items doc generation function
r13593 continue
text = gettext(text)
Gregory Szorc
help: teach topic symbols how to dedent...
r24098 if dedent:
Augie Fackler
help: work around textwrap.dedent() only working on strings
r32549 # Abuse latin1 to use textwrap.dedent() on bytes.
text = textwrap.dedent(text.decode('latin1')).encode('latin1')
Patrick Mezard
help: extract items doc generation function
r13593 lines = text.splitlines()
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 doclines = [lines[0]]
"Yann E. MORIN"
help: strip doctest from dochelp...
r16250 for l in lines[1:]:
# Stop once we find some Python doctest
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if l.strip().startswith(b'>>>'):
"Yann E. MORIN"
help: strip doctest from dochelp...
r16250 break
Gregory Szorc
help: teach topic symbols how to dedent...
r24098 if dedent:
doclines.append(l.rstrip())
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doclines.append(b' ' + l.strip())
entries.append(b'\n'.join(doclines))
entries = b'\n\n'.join(entries)
Patrick Mezard
help: extract items doc generation function
r13593 return doc.replace(marker, entries)
Matt Mackall
help: consolidate topic hooks in help.py...
r14318
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
help: teach topic symbols how to dedent...
r24098 def addtopicsymbols(topic, marker, symbols, dedent=False):
Yuya Nishihara
help: pass around ui to rewriter hooks (API)...
r26414 def add(ui, topic, doc):
return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
help: consolidate topic hooks in help.py...
r14318 addtopichook(topic, add)
Augie Fackler
formatting: blacken the codebase...
r43346
addtopicsymbols(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'bundlespec',
b'.. bundlecompressionmarker',
Augie Fackler
formatting: blacken the codebase...
r43346 compression.bundlecompressiontopics(),
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 addtopicsymbols(b'filesets', b'.. predicatesmarker', fileset.symbols)
Augie Fackler
formatting: blacken the codebase...
r43346 addtopicsymbols(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'merge-tools', b'.. internaltoolsmarker', filemerge.internalsdoc
)
addtopicsymbols(b'revisions', b'.. predicatesmarker', revset.symbols)
addtopicsymbols(b'templates', b'.. keywordsmarker', templatekw.keywords)
addtopicsymbols(b'templates', b'.. filtersmarker', templatefilters.filters)
addtopicsymbols(b'templates', b'.. functionsmarker', templatefuncs.funcs)
addtopicsymbols(
b'hgweb', b'.. webcommandsmarker', webcommands.commands, dedent=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 def inserttweakrc(ui, topic, doc):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 marker = b'.. tweakdefaultsmarker'
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 repl = uimod.tweakrc
Augie Fackler
formatting: blacken the codebase...
r43346
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 def sub(m):
lines = [m.group(1) + s for s in repl.splitlines()]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'\n'.join(lines)
Augie Fackler
formatting: blacken the codebase...
r43346
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472 return re.sub(br'( *)%s' % re.escape(marker), sub, doc)
Augie Fackler
formatting: blacken the codebase...
r43346
Ludovic Chabant
help: extract logic for listing commands and topics...
r46218 def _getcategorizedhelpcmds(ui, cmdtable, name, select=None):
# Category -> list of commands
cats = {}
# Command -> short description
h = {}
# Command -> string showing synonyms
syns = {}
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for c, e in cmdtable.items():
Ludovic Chabant
help: extract logic for listing commands and topics...
r46218 fs = cmdutil.parsealiases(c)
f = fs[0]
syns[f] = fs
func = e[0]
if select and not select(f):
continue
doc = pycompat.getdoc(func)
if filtercmd(ui, f, func, name, doc):
continue
doc = gettext(doc)
if not doc:
doc = _(b"(no help text available)")
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 h[f] = stringutil.firstline(doc).rstrip()
Ludovic Chabant
help: extract logic for listing commands and topics...
r46218
cat = getattr(func, 'helpcategory', None) or (
registrar.command.CATEGORY_NONE
)
cats.setdefault(cat, []).append(f)
return cats, h, syns
def _getcategorizedhelptopics(ui, topictable):
# Group commands by category.
topiccats = {}
syns = {}
for topic in topictable:
names, header, doc = topic[0:3]
if len(topic) > 3 and topic[3]:
category = topic[3]
else:
category = TOPIC_CATEGORY_NONE
topicname = names[0]
syns[topicname] = list(names)
if not filtertopic(ui, topicname):
topiccats.setdefault(category, []).append((topicname, header))
return topiccats, syns
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 addtopichook(b'config', inserttweakrc)
Valentin Gatien-Baron
help: describe what ui.tweakdefaults changes, concretely...
r40472
Augie Fackler
formatting: blacken the codebase...
r43346
def help_(
ui,
commands,
name,
unknowncmd=False,
full=True,
subtopic=None,
fullname=None,
**opts
):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 Generate the help for 'name' as unformatted restructured text. If
'name' is None, describe the commands available.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Pulkit Goyal
py3: make sure opts are passed and used correctly in help command...
r32143 opts = pycompat.byteskwargs(opts)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Gregory Szorc
help: pass sub-topic into help query functions...
r27378 def helpcmd(name, subtopic=None):
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 try:
Augie Fackler
formatting: blacken the codebase...
r43346 aliases, entry = cmdutil.findcmd(
name, commands.table, strict=unknowncmd
)
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except error.AmbiguousCommand as inst:
Martijn Pieters
py3: use py3 as the test tag, dropping the k...
r40299 # py3 fix: except vars can't be used outside the scope of the
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 # except block, nor can be used inside a lambda. python issue4617
Martin von Zweigbergk
errors: name arguments to AmbiguousCommand constructor...
r46271 prefix = inst.prefix
Yuya Nishihara
help: use cmdutil.parsealiases() to resolve command name...
r36264 select = lambda c: cmdutil.parsealiases(c)[0].startswith(prefix)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 rst = helplist(select)
return rst
rst = []
# check if it's an invalid alias and display its error if it is
Yuya Nishihara
alias: keep error message in "badalias" so that help can see it...
r22160 if getattr(entry[0], 'badalias', None):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(entry[0].badalias + b'\n')
Yuya Nishihara
help: provide help of bad alias without executing aliascmd()...
r22162 if entry[0].unknowncmd:
try:
rst.extend(helpextcmd(entry[0].cmdname))
except error.UnknownCommand:
pass
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 return rst
# synopsis
if len(entry) > 2:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if entry[2].startswith(b'hg'):
rst.append(b"%s\n" % entry[2])
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'hg %s %s\n' % (aliases[0], entry[2]))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'hg %s\n' % aliases[0])
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 # aliases
if full and not ui.quiet and len(aliases) > 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(_(b"\naliases: %s\n") % b', '.join(aliases[1:]))
rst.append(b'\n')
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
# description
Yuya Nishihara
py3: convert __doc__ back to bytes in help.py...
r32615 doc = gettext(pycompat.getdoc(entry[0]))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if not doc:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doc = _(b"(no help text available)")
if util.safehasattr(entry[0], b'definition'): # aliased command
timeless
help: report source of aliases
r28828 source = entry[0].source
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if entry[0].definition.startswith(b'!'): # shell alias
doc = _(b'shell alias for: %s\n\n%s\n\ndefined by: %s\n') % (
Augie Fackler
formatting: blacken the codebase...
r43346 entry[0].definition[1:],
doc,
source,
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doc = _(b'alias for: hg %s\n\n%s\n\ndefined by: %s\n') % (
Augie Fackler
formatting: blacken the codebase...
r43346 entry[0].definition,
doc,
source,
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 doc = doc.splitlines(True)
if ui.quiet or not full:
rst.append(doc[0])
else:
rst.extend(doc)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n')
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
# check if this command shadows a non-trivial (multi-line)
# extension help text
try:
mod = extensions.find(name)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doc = gettext(pycompat.getdoc(mod)) or b''
if b'\n' in doc.strip():
Augie Fackler
formatting: blacken the codebase...
r43346 msg = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"(use 'hg help -e %s' to show help for "
b"the %s extension)"
Augie Fackler
formatting: blacken the codebase...
r43346 ) % (name, name)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n%s\n' % msg)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 except KeyError:
pass
# options
if not ui.quiet and entry[1]:
Valentin Gatien-Baron
help: add a mechanism to change flags' help depending on config...
r44777 rst.append(optrst(_(b"options"), entry[1], ui.verbose, ui))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
if ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
Augie Fackler
cleanup: re-run black on the codebase...
r44787 optrst(
_(b"global options"), commands.globalopts, ui.verbose, ui
)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
if not ui.verbose:
if not full:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(_(b"\n(use 'hg %s -h' to show more help)\n") % name)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 elif not ui.quiet:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'\n(some details hidden, use --verbose '
b'to show complete help)'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
return rst
timeless
help: fix help -c/help -e/help -k...
r27325 def helplist(select=None, **opts):
Ludovic Chabant
help: extract logic for listing commands and topics...
r46218 cats, h, syns = _getcategorizedhelpcmds(
ui, commands.table, name, select
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
rst = []
if not h:
if not ui.quiet:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(_(b'no commands defined\n'))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 return rst
rdamazio@google.com
help: adding support for command categories...
r40327 # Output top header.
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if not ui.quiet:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name == b"shortlist":
rst.append(_(b'basic commands:\n\n'))
elif name == b"debug":
rst.append(_(b'debug commands (internal and unsupported):\n\n'))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(_(b'list of commands:\n'))
rdamazio@google.com
help: adding support for command categories...
r40327
def appendcmds(cmds):
cmds = sorted(cmds)
for c in cmds:
help: escape ':' (as '\:') when generating command names...
r47115 display_cmd = c
rdamazio@google.com
help: adding support for command categories...
r40327 if ui.verbose:
help: escape ':' (as '\:') when generating command names...
r47115 display_cmd = b', '.join(syns[c])
display_cmd = display_cmd.replace(b':', br'\:')
rst.append(b' :%s: %s\n' % (display_cmd, h[c]))
rdamazio@google.com
help: adding support for command categories...
r40327
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name in (b'shortlist', b'debug'):
rdamazio@google.com
help: adding support for command categories...
r40327 # List without categories.
appendcmds(h)
else:
# Check that all categories have an order.
missing_order = set(cats.keys()) - set(CATEGORY_ORDER)
if missing_order:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.develwarn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'help categories missing from CATEGORY_ORDER: %s'
Augie Fackler
formatting: blacken the codebase...
r43346 % missing_order
)
rdamazio@google.com
help: adding support for command categories...
r40327
# List per category.
for cat in CATEGORY_ORDER:
catfns = cats.get(cat, [])
if catfns:
if len(cats) > 1:
catname = gettext(CATEGORY_NAMES[cat])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b"\n%s:\n" % catname)
rst.append(b"\n")
rdamazio@google.com
help: adding support for command categories...
r40327 appendcmds(catfns)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
timeless
help: fix help -c/help -e/help -k...
r27325 ex = opts.get
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 anyopts = ex('keyword') or not (ex('command') or ex('extension'))
timeless
help: fix help -c/help -e/help -k...
r27325 if not name and anyopts:
Augie Fackler
formatting: blacken the codebase...
r43346 exts = listexts(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'enabled extensions:'),
Augie Fackler
formatting: blacken the codebase...
r43346 extensions.enabled(),
showdeprecated=ui.verbose,
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if exts:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n')
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 rst.extend(exts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(_(b"\nadditional help topics:\n"))
Ludovic Chabant
help: extract logic for listing commands and topics...
r46218 topiccats, topicsyns = _getcategorizedhelptopics(ui, helptable)
Rodrigo Damazio
help: splitting the topics by category...
r40328
# Check that all categories have an order.
missing_order = set(topiccats.keys()) - set(TOPIC_CATEGORY_ORDER)
if missing_order:
ui.develwarn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'help categories missing from TOPIC_CATEGORY_ORDER: %s'
Augie Fackler
formatting: blacken the codebase...
r43346 % missing_order
)
Rodrigo Damazio
help: splitting the topics by category...
r40328
# Output topics per category.
for cat in TOPIC_CATEGORY_ORDER:
topics = topiccats.get(cat, [])
if topics:
if len(topiccats) > 1:
catname = gettext(TOPIC_CATEGORY_NAMES[cat])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b"\n%s:\n" % catname)
rst.append(b"\n")
Rodrigo Damazio
help: splitting the topics by category...
r40328 for t, desc in topics:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b" :%s: %s\n" % (t, desc))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Matt Mackall
help: refactor helplist optlist mess...
r22115 if ui.quiet:
pass
elif ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'\n%s\n'
Augie Fackler
cleanup: re-run black on the codebase...
r44787 % optrst(
_(b"global options"), commands.globalopts, ui.verbose, ui
)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name == b'shortlist':
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"\n(use 'hg help' for the full list of commands)\n")
Augie Fackler
formatting: blacken the codebase...
r43346 )
Matt Mackall
help: refactor helplist optlist mess...
r22115 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name == b'shortlist':
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"\n(use 'hg help' for the full list of commands "
b"or 'hg -v' for details)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Matt Mackall
help: refactor helplist optlist mess...
r22115 elif name and not full:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"\n(use 'hg help %s' to show the full help text)\n")
Augie Fackler
formatting: blacken the codebase...
r43346 % name
)
rdamazio@google.com
help: adding support for command categories...
r40327 elif name and syns and name in syns.keys():
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"\n(use 'hg help -v -e %s' to show built-in "
b"aliases and global options)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% name
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"\n(use 'hg help -v%s' to show built-in aliases "
b"and global options)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 % (name and b" " + name or b"")
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 return rst
Gregory Szorc
help: pass sub-topic into help query functions...
r27378 def helptopic(name, subtopic=None):
Gregory Szorc
help: support loading sub-topics...
r27379 # 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
Nathan Goldbaum
help: check if a subtopic exists and raise an error if it doesn't (issue6145)...
r42585 if not any(subtopic in s[0] for s in subtopics[name]):
raise error.UnknownCommand(name)
Gregory Szorc
help: support loading sub-topics...
r27379
if not header:
Rodrigo Damazio
help: splitting the topics by category...
r40328 for topic in helptable:
names, header, doc = topic[0:3]
Gregory Szorc
help: support loading sub-topics...
r27379 if name in names:
break
else:
raise error.UnknownCommand(name)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Dan Villiom Podlaski Christiansen
help: use a full header for topic titles...
r18748 rst = [minirst.section(header)]
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 # description
if not doc:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b" %s\n" % _(b"(no help text available)"))
Augie Fackler
help: restore use of callable() since it was readded in Python 3.2
r21796 if callable(doc):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst += [b" %s\n" % l for l in doc(ui).splitlines()]
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
if not ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 omitted = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'(some details hidden, use --verbose'
b' to show complete help)'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 indicateomitted(rst, omitted)
try:
cmdutil.findcmd(name, commands.table)
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"\nuse 'hg help -c %s' to see help for the %s command\n")
Augie Fackler
formatting: blacken the codebase...
r43346 % (name, name)
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 except error.UnknownCommand:
pass
return rst
Gregory Szorc
help: pass sub-topic into help query functions...
r27378 def helpext(name, subtopic=None):
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 try:
mod = extensions.find(name)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 doc = gettext(pycompat.getdoc(mod)) or _(b'no help text available')
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 except KeyError:
mod = None
Gregory Szorc
extensions: refactor function for obtaining disabled extension help...
r45145 doc = extensions.disabled_help(name)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if not doc:
raise error.UnknownCommand(name)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'\n' not in doc:
head, tail = doc, b""
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 head, tail = doc.split(b'\n', 1)
rst = [_(b'%s extension - %s\n\n') % (name.rpartition(b'.')[-1], head)]
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if tail:
rst.extend(tail.splitlines(True))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n')
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
if not ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 omitted = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'(some details hidden, use --verbose'
b' to show complete help)'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 indicateomitted(rst, omitted)
if mod:
try:
ct = mod.cmdtable
except AttributeError:
ct = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 modcmds = {c.partition(b'|')[0] for c in ct}
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 rst.extend(helplist(modcmds.__contains__))
else:
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"(use 'hg help extensions' for information on enabling"
b" extensions)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 return rst
Gregory Szorc
help: pass sub-topic into help query functions...
r27378 def helpextcmd(name, subtopic=None):
Augie Fackler
formatting: blacken the codebase...
r43346 cmd, ext, doc = extensions.disabledcmd(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui, name, ui.configbool(b'ui', b'strict')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
help: use new function for getting first line of string...
r49888 doc = stringutil.firstline(doc)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Augie Fackler
formatting: blacken the codebase...
r43346 rst = listexts(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"'%s' is provided by the following extension:") % cmd,
Augie Fackler
formatting: blacken the codebase...
r43346 {ext: doc},
indent=4,
showdeprecated=True,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n')
Augie Fackler
formatting: blacken the codebase...
r43346 rst.append(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"(use 'hg help extensions' for information on enabling "
b"extensions)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 return rst
rst = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 kw = opts.get(b'keyword')
timeless
help: fix help -c/help -e/help -k...
r27325 if kw or name is None and any(opts[o] for o in opts):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 matches = topicmatch(ui, commands, name or b'')
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 helpareas = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'extension'):
helpareas += [(b'extensions', _(b'Extensions'))]
if opts.get(b'command'):
helpareas += [(b'commands', _(b'Commands'))]
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 if not helpareas:
Augie Fackler
formatting: blacken the codebase...
r43346 helpareas = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'topics', _(b'Topics')),
(b'commands', _(b'Commands')),
(b'extensions', _(b'Extensions')),
(b'extensioncommands', _(b'Extension Commands')),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 for t, title in helpareas:
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if matches[t]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'%s:\n\n' % title)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 rst.extend(minirst.maketable(sorted(matches[t]), 1))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst.append(b'\n')
Pierre-Yves David
help: provide a more helpful message when no keyword are matched...
r21288 if not rst:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b'no matches')
hint = _(b"try 'hg help' for a list of topics")
Martin von Zweigbergk
errors: raise InputError when non-existent help section requested...
r46887 raise error.InputError(msg, hint=hint)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif name and name != b'shortlist':
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 queries = []
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 if unknowncmd:
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 queries += [helpextcmd]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'extension'):
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 queries += [helpext]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'command'):
timeless@mozdev.org
help: fix help argument parsing and documentation...
r26238 queries += [helpcmd]
if not queries:
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 queries = (helptopic, helpcmd, helpext, helpextcmd)
for f in queries:
try:
Gregory Szorc
help: pass sub-topic into help query functions...
r27378 rst = f(name, subtopic)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 break
Pierre-Yves David
help: suggest keyword search when no topic is found...
r21289 except error.UnknownCommand:
pass
else:
if unknowncmd:
raise error.UnknownCommand(name)
else:
Nathan Goldbaum
help: include subtopic in error message if passed...
r42586 if fullname:
formatname = fullname
else:
formatname = name
if subtopic:
hintname = subtopic
else:
hintname = name
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b'no such help topic: %s') % formatname
hint = _(b"try 'hg help --keyword %s'") % hintname
Martin von Zweigbergk
errors: raise InputError when non-existent help section requested...
r46887 raise error.InputError(msg, hint=hint)
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746 else:
# program name
if not ui.quiet:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rst = [_(b"Mercurial Distributed SCM\n"), b'\n']
Augie Fackler
help: convert dict to strkwargs
r32547 rst.extend(helplist(None, **pycompat.strkwargs(opts)))
Dan Villiom Podlaski Christiansen
help: move the majority of the help command to the help module...
r18746
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(rst)
Augie Fackler
help: move rst formatting of help documents into help.py...
r31059
Augie Fackler
formatting: blacken the codebase...
r43346
def formattedhelp(
ui, commands, fullname, keep=None, unknowncmd=False, full=True, **opts
):
Augie Fackler
help: move rst formatting of help documents into help.py...
r31059 """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 = []
Augie Fackler
help: avoid mutating passed-in `keep` list in `formattedhelp`
r31265 else:
Augie Fackler
formatting: blacken the codebase...
r43346 keep = list(keep) # make a copy so we can mutate this later
Yuya Nishihara
help: rewrite parsing of help topic to not drop section name with dots...
r39375
# <fullname> := <name>[.<subtopic][.<section>]
name = subtopic = section = None
if fullname is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 nameparts = fullname.split(b'.')
Yuya Nishihara
help: rewrite parsing of help topic to not drop section name with dots...
r39375 name = nameparts.pop(0)
if nameparts and name in subtopics:
subtopic = nameparts.pop(0)
if nameparts:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 section = encoding.lower(b'.'.join(nameparts))
Yuya Nishihara
help: rewrite parsing of help topic to not drop section name with dots...
r39375
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 textwidth = ui.configint(b'ui', b'textwidth')
Augie Fackler
help: move rst formatting of help documents into help.py...
r31059 termwidth = ui.termwidth() - 2
if textwidth <= 0 or termwidth < textwidth:
textwidth = termwidth
Augie Fackler
formatting: blacken the codebase...
r43346 text = help_(
ui,
commands,
name,
fullname=fullname,
subtopic=subtopic,
unknowncmd=unknowncmd,
full=full,
**opts
)
Augie Fackler
help: move rst formatting of help documents into help.py...
r31059
Yuya Nishihara
help: inline minirst.format()...
r39344 blocks, pruned = minirst.parse(text, keep=keep)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'verbose' in pruned:
keep.append(b'omitted')
Augie Fackler
help: move rst formatting of help documents into help.py...
r31059 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 keep.append(b'notomitted')
Yuya Nishihara
help: inline minirst.format()...
r39344 blocks, pruned = minirst.parse(text, keep=keep)
if section:
blocks = minirst.filtersections(blocks, section)
Yuya Nishihara
help: reorder section filtering flow to not format help text twice
r39345
# 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 (blocks and name):
Martin von Zweigbergk
errors: raise InputError when non-existent help section requested...
r46887 raise error.InputError(_(b"help section not found: %s") % fullname)
Yuya Nishihara
help: reorder section filtering flow to not format help text twice
r39345
Yuya Nishihara
help: inline minirst.format()...
r39344 return minirst.formatplain(blocks, textwidth)