help.py
1148 lines
| 36.0 KiB
| text/x-python
|
PythonLexer
/ mercurial / help.py
Matt Mackall
|
r3795 | # help.py - help data for mercurial | ||
# | ||||
# Copyright 2006 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
Matt Mackall
|
r3795 | |||
Gregory Szorc
|
r27479 | from __future__ import absolute_import | ||
import itertools | ||||
Valentin Gatien-Baron
|
r40472 | import re | ||
Gregory Szorc
|
r27479 | import textwrap | ||
from .i18n import ( | ||||
_, | ||||
gettext, | ||||
) | ||||
Gregory Szorc
|
r43359 | from .pycompat import getattr | ||
Gregory Szorc
|
r27479 | from . import ( | ||
cmdutil, | ||||
encoding, | ||||
error, | ||||
extensions, | ||||
Daniel Ploch
|
r37109 | fancyopts, | ||
Gregory Szorc
|
r27479 | filemerge, | ||
fileset, | ||||
minirst, | ||||
Pulkit Goyal
|
r32143 | pycompat, | ||
rdamazio@google.com
|
r40327 | registrar, | ||
Gregory Szorc
|
r27479 | revset, | ||
templatefilters, | ||||
Yuya Nishihara
|
r36940 | templatefuncs, | ||
Gregory Szorc
|
r27479 | templatekw, | ||
Valentin Gatien-Baron
|
r40472 | ui as uimod, | ||
Gregory Szorc
|
r27479 | util, | ||
) | ||||
Augie Fackler
|
r43346 | from .hgweb import webcommands | ||
Martin von Zweigbergk
|
r44070 | from .utils import ( | ||
compression, | ||||
resourceutil, | ||||
) | ||||
Cédric Duval
|
r8863 | |||
Martin von Zweigbergk
|
r32291 | _exclkeywords = { | ||
Augie Fackler
|
r43347 | b"(ADVANCED)", | ||
b"(DEPRECATED)", | ||||
b"(EXPERIMENTAL)", | ||||
Jun Wu
|
r31080 | # i18n: "(ADVANCED)" is a keyword, must be translated consistently | ||
Augie Fackler
|
r43347 | _(b"(ADVANCED)"), | ||
Yuya Nishihara
|
r26370 | # i18n: "(DEPRECATED)" is a keyword, must be translated consistently | ||
Augie Fackler
|
r43347 | _(b"(DEPRECATED)"), | ||
Yuya Nishihara
|
r26370 | # i18n: "(EXPERIMENTAL)" is a keyword, must be translated consistently | ||
Augie Fackler
|
r43347 | _(b"(EXPERIMENTAL)"), | ||
Martin von Zweigbergk
|
r32291 | } | ||
Yuya Nishihara
|
r26369 | |||
rdamazio@google.com
|
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
|
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
|
r43346 | registrar.command.CATEGORY_CHANGE_NAVIGATION, | ||
rdamazio@google.com
|
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
|
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
|
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
|
r40327 | } | ||
Rodrigo Damazio
|
r40328 | # Topic categories. | ||
Augie Fackler
|
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
|
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
|
r40330 | TOPIC_CATEGORY_IDS, | ||
TOPIC_CATEGORY_OUTPUT, | ||||
TOPIC_CATEGORY_CONFIG, | ||||
TOPIC_CATEGORY_CONCEPTS, | ||||
TOPIC_CATEGORY_MISC, | ||||
Rodrigo Damazio
|
r40328 | TOPIC_CATEGORY_NONE, | ||
] | ||||
# Human-readable topic category names. These are translated. | ||||
TOPIC_CATEGORY_NAMES = { | ||||
Augie Fackler
|
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
|
r40328 | } | ||
Augie Fackler
|
r43346 | |||
Augie Fackler
|
r20582 | def listexts(header, exts, indent=1, showdeprecated=False): | ||
Cédric Duval
|
r8879 | '''return a text listing of the given extensions''' | ||
Olav Reinert
|
r16852 | rst = [] | ||
if exts: | ||||
Gregory Szorc
|
r43376 | for name, desc in sorted(pycompat.iteritems(exts)): | ||
Yuya Nishihara
|
r26371 | if not showdeprecated and any(w in desc for w in _exclkeywords): | ||
Augie Fackler
|
r20582 | continue | ||
Augie Fackler
|
r43347 | rst.append(b'%s:%s: %s\n' % (b' ' * indent, name, desc)) | ||
timeless
|
r27151 | if rst: | ||
Augie Fackler
|
r43347 | rst.insert(0, b'\n%s\n\n' % header) | ||
Olav Reinert
|
r16852 | return rst | ||
Cédric Duval
|
r8864 | |||
Augie Fackler
|
r43346 | |||
Yuya Nishihara
|
r26413 | def extshelp(ui): | ||
Augie Fackler
|
r43347 | rst = loaddoc(b'extensions')(ui).splitlines(True) | ||
Augie Fackler
|
r43346 | rst.extend( | ||
listexts( | ||||
Augie Fackler
|
r43347 | _(b'enabled extensions:'), extensions.enabled(), showdeprecated=True | ||
Augie Fackler
|
r43346 | ) | ||
) | ||||
rst.extend( | ||||
listexts( | ||||
Augie Fackler
|
r43347 | _(b'disabled extensions:'), | ||
Augie Fackler
|
r43346 | extensions.disabled(), | ||
showdeprecated=ui.verbose, | ||||
) | ||||
) | ||||
Augie Fackler
|
r43347 | doc = b''.join(rst) | ||
Cédric Duval
|
r8863 | return doc | ||
Martin Geisler
|
r7013 | |||
Augie Fackler
|
r44787 | |||
Valentin Gatien-Baron
|
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
|
r44787 | item = text[pos + len(marker) : -1] | ||
Valentin Gatien-Baron
|
r44777 | return text[:pos], item.split(b'.', 2) | ||
Augie Fackler
|
r43346 | |||
Augie Fackler
|
r44787 | |||
Valentin Gatien-Baron
|
r44777 | def optrst(header, options, verbose, ui): | ||
Olav Reinert
|
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
|
r43347 | optlabel = _(b"VALUE") # default label | ||
Olav Reinert
|
r16781 | |||
Yuya Nishihara
|
r26369 | if not verbose and any(w in desc for w in _exclkeywords): | ||
Olav Reinert
|
r16781 | continue | ||
Valentin Gatien-Baron
|
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
|
r43347 | so = b'' | ||
Olav Reinert
|
r16781 | if shortopt: | ||
Augie Fackler
|
r43347 | so = b'-' + shortopt | ||
lo = b'--' + longopt | ||||
Martin von Zweigbergk
|
r41045 | if default is True: | ||
Augie Fackler
|
r43347 | lo = b'--[no-]' + longopt | ||
Daniel Ploch
|
r37109 | |||
if isinstance(default, fancyopts.customopt): | ||||
Daniel Ploch
|
r37110 | default = default.getdefaultvalue() | ||
Martin von Zweigbergk
|
r41046 | if default and not callable(default): | ||
Augie Fackler
|
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
|
r40989 | defaultstr = pycompat.bytestr(default) | ||
Martin von Zweigbergk
|
r41046 | if default is True: | ||
Augie Fackler
|
r43347 | defaultstr = _(b"on") | ||
Valentin Gatien-Baron
|
r44777 | desc += _(b" (default: %s)") % (defaultstr + defaultstrsuffix) | ||
Olav Reinert
|
r16781 | |||
if isinstance(default, list): | ||||
Augie Fackler
|
r43347 | lo += b" %s [+]" % optlabel | ||
Olav Reinert
|
r16781 | multioccur = True | ||
elif (default is not None) and not isinstance(default, bool): | ||||
Augie Fackler
|
r43347 | lo += b" %s" % optlabel | ||
Olav Reinert
|
r16781 | |||
data.append((so, lo, desc)) | ||||
Matt Mackall
|
r22117 | if multioccur: | ||
Augie Fackler
|
r43347 | header += _(b" ([+] can be repeated)") | ||
Olav Reinert
|
r16781 | |||
Augie Fackler
|
r43347 | rst = [b'\n%s:\n\n' % header] | ||
Matt Mackall
|
r22116 | rst.extend(minirst.maketable(data, 1)) | ||
Olav Reinert
|
r16781 | |||
Augie Fackler
|
r43347 | return b''.join(rst) | ||
Olav Reinert
|
r16781 | |||
Augie Fackler
|
r43346 | |||
FUJIWARA Katsunori
|
r17837 | def indicateomitted(rst, omitted, notomitted=None): | ||
Augie Fackler
|
r43347 | rst.append(b'\n\n.. container:: omitted\n\n %s\n\n' % omitted) | ||
FUJIWARA Katsunori
|
r17837 | if notomitted: | ||
Augie Fackler
|
r43347 | rst.append(b'\n\n.. container:: notomitted\n\n %s\n\n' % notomitted) | ||
FUJIWARA Katsunori
|
r17837 | |||
Augie Fackler
|
r43346 | |||
rdamazio@google.com
|
r40450 | def filtercmd(ui, cmd, func, kw, doc): | ||
Augie Fackler
|
r43347 | if not ui.debugflag and cmd.startswith(b"debug") and kw != b"debug": | ||
rdamazio@google.com
|
r40450 | # Debug command, and user is not looking for those. | ||
timeless
|
r27323 | return True | ||
rdamazio@google.com
|
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
|
r43347 | if kw == b"shortlist" and not getattr(func, 'helpbasic', False): | ||
rdamazio@google.com
|
r40450 | # We're presenting the short list but the command is not basic. | ||
timeless
|
r27323 | return True | ||
Augie Fackler
|
r43347 | if ui.configbool(b'help', b'hidden-command.%s' % cmd): | ||
rdamazio@google.com
|
r40450 | # Configuration explicitly hides the command. | ||
timeless
|
r27323 | return True | ||
return False | ||||
Augie Fackler
|
r43346 | |||
rdamazio@google.com
|
r40449 | def filtertopic(ui, topic): | ||
Augie Fackler
|
r43347 | return ui.configbool(b'help', b'hidden-topic.%s' % topic, False) | ||
rdamazio@google.com
|
r40449 | |||
Augie Fackler
|
r43346 | |||
Yuya Nishihara
|
r32567 | def topicmatch(ui, commands, kw): | ||
Augie Fackler
|
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
|
r43346 | |||
Augie Fackler
|
r16710 | def lowercontains(container): | ||
Nikolaj Sjujskij
|
r16845 | return kw in encoding.lower(container) # translated in helptable | ||
Augie Fackler
|
r43346 | |||
results = { | ||||
Augie Fackler
|
r43347 | b'topics': [], | ||
b'commands': [], | ||||
b'extensions': [], | ||||
b'extensioncommands': [], | ||||
Augie Fackler
|
r43346 | } | ||
Rodrigo Damazio
|
r40328 | for topic in helptable: | ||
names, header, doc = topic[0:3] | ||||
Gregory Szorc
|
r22322 | # Old extensions may use a str as doc. | ||
Augie Fackler
|
r43346 | if ( | ||
sum(map(lowercontains, names)) | ||||
Augie Fackler
|
r16710 | or lowercontains(header) | ||
Augie Fackler
|
r43346 | or (callable(doc) and lowercontains(doc(ui))) | ||
): | ||||
rdamazio@google.com
|
r40449 | name = names[0] | ||
if not filtertopic(ui, name): | ||||
Augie Fackler
|
r43347 | results[b'topics'].append((names[0], header)) | ||
Gregory Szorc
|
r43376 | for cmd, entry in pycompat.iteritems(commands.table): | ||
Augie Fackler
|
r16710 | if len(entry) == 3: | ||
summary = entry[2] | ||||
else: | ||||
Augie Fackler
|
r43347 | summary = b'' | ||
Nikolaj Sjujskij
|
r16845 | # translate docs *before* searching there | ||
rdamazio@google.com
|
r40450 | func = entry[0] | ||
Augie Fackler
|
r43347 | docs = _(pycompat.getdoc(func)) or b'' | ||
Augie Fackler
|
r16710 | if kw in cmd or lowercontains(summary) or lowercontains(docs): | ||
Nikolaj Sjujskij
|
r16845 | doclines = docs.splitlines() | ||
Augie Fackler
|
r16710 | if doclines: | ||
summary = doclines[0] | ||||
Yuya Nishihara
|
r36264 | cmdname = cmdutil.parsealiases(cmd)[0] | ||
rdamazio@google.com
|
r40450 | if filtercmd(ui, cmdname, func, kw, docs): | ||
timeless
|
r27324 | continue | ||
Augie Fackler
|
r43347 | results[b'commands'].append((cmdname, summary)) | ||
Augie Fackler
|
r16710 | for name, docs in itertools.chain( | ||
Gregory Szorc
|
r43376 | pycompat.iteritems(extensions.enabled(False)), | ||
pycompat.iteritems(extensions.disabled()), | ||||
Augie Fackler
|
r43346 | ): | ||
Simon Farnsworth
|
r28058 | if not docs: | ||
continue | ||||
Augie Fackler
|
r43347 | name = name.rpartition(b'.')[-1] | ||
Augie Fackler
|
r16710 | if lowercontains(name) or lowercontains(docs): | ||
Nikolaj Sjujskij
|
r16845 | # extension docs are already translated | ||
Augie Fackler
|
r43347 | results[b'extensions'].append((name, docs.splitlines()[0])) | ||
Yuya Nishihara
|
r34913 | try: | ||
Augie Fackler
|
r43347 | mod = extensions.load(ui, name, b'') | ||
Yuya Nishihara
|
r34913 | except ImportError: | ||
# debug message would be printed in extensions.load() | ||||
continue | ||||
Gregory Szorc
|
r43376 | for cmd, entry in pycompat.iteritems(getattr(mod, 'cmdtable', {})): | ||
Augie Fackler
|
r16711 | if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): | ||
Yuya Nishihara
|
r36264 | cmdname = cmdutil.parsealiases(cmd)[0] | ||
rdamazio@google.com
|
r40450 | func = entry[0] | ||
cmddoc = pycompat.getdoc(func) | ||||
Yuya Nishihara
|
r32615 | if cmddoc: | ||
cmddoc = gettext(cmddoc).splitlines()[0] | ||||
Thomas Arendsen Hein
|
r16884 | else: | ||
Augie Fackler
|
r43347 | cmddoc = _(b'(no help text available)') | ||
rdamazio@google.com
|
r40450 | if filtercmd(ui, cmdname, func, kw, cmddoc): | ||
timeless
|
r27387 | continue | ||
Augie Fackler
|
r43347 | results[b'extensioncommands'].append((cmdname, cmddoc)) | ||
Augie Fackler
|
r16710 | return results | ||
Augie Fackler
|
r43346 | |||
Gregory Szorc
|
r27375 | def loaddoc(topic, subdir=None): | ||
Martin Geisler
|
r9539 | """Return a delayed loader for help/topic.txt.""" | ||
Matt Mackall
|
r3798 | |||
Yuya Nishihara
|
r26413 | def loader(ui): | ||
Matt Harbison
|
r44479 | package = b'mercurial.helptext' | ||
Gregory Szorc
|
r27375 | if subdir: | ||
Matt Harbison
|
r44479 | package += b'.' + subdir | ||
Martin von Zweigbergk
|
r44323 | with resourceutil.open_resource(package, topic + b'.txt') as fp: | ||
doc = gettext(fp.read()) | ||||
Patrick Mezard
|
r12820 | for rewriter in helphooks.get(topic, []): | ||
Yuya Nishihara
|
r26414 | doc = rewriter(ui, topic, doc) | ||
Patrick Mezard
|
r12820 | return doc | ||
Martin Geisler
|
r9539 | return loader | ||
Alexander Solovyov
|
r7677 | |||
Augie Fackler
|
r43346 | |||
internalstable = sorted( | ||||
[ | ||||
r45619 | ( | |||
[b'bid-merge'], | ||||
_(b'Bid Merge Algorithm'), | ||||
loaddoc(b'bid-merge', subdir=b'internals'), | ||||
), | ||||
Augie Fackler
|
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
|
r43346 | ( | ||
Augie Fackler
|
r43347 | [b'changegroups'], | ||
_(b'Changegroups'), | ||||
loaddoc(b'changegroups', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'config'], | ||
_(b'Config Registrar'), | ||||
loaddoc(b'config', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'extensions', b'extension'], | ||
_(b'Extension API'), | ||||
loaddoc(b'extensions', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'mergestate'], | ||
_(b'Mergestate'), | ||||
loaddoc(b'mergestate', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'requirements'], | ||
_(b'Repository Requirements'), | ||||
loaddoc(b'requirements', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'revlogs'], | ||
_(b'Revision Logs'), | ||||
loaddoc(b'revlogs', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'wireprotocol'], | ||
_(b'Wire Protocol'), | ||||
loaddoc(b'wireprotocol', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'wireprotocolrpc'], | ||
_(b'Wire Protocol RPC'), | ||||
loaddoc(b'wireprotocolrpc', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
( | ||||
Augie Fackler
|
r43347 | [b'wireprotocolv2'], | ||
_(b'Wire Protocol Version 2'), | ||||
loaddoc(b'wireprotocolv2', subdir=b'internals'), | ||||
Augie Fackler
|
r43346 | ), | ||
] | ||||
) | ||||
Gregory Szorc
|
r27376 | |||
def internalshelp(ui): | ||||
"""Generate the index for the "internals" topic.""" | ||||
Augie Fackler
|
r43346 | lines = [ | ||
Augie Fackler
|
r43347 | b'To access a subtopic, use "hg help internals.{subtopic-name}"\n', | ||
b'\n', | ||||
Augie Fackler
|
r43346 | ] | ||
Gregory Szorc
|
r27376 | for names, header, doc in internalstable: | ||
Augie Fackler
|
r43347 | lines.append(b' :%s: %s\n' % (names[0], header)) | ||
Gregory Szorc
|
r27376 | |||
Augie Fackler
|
r43347 | return b''.join(lines) | ||
Gregory Szorc
|
r27376 | |||
Augie Fackler
|
r43346 | |||
helptable = sorted( | ||||
[ | ||||
( | ||||
Augie Fackler
|
r43347 | [b'bundlespec'], | ||
_(b"Bundle File Formats"), | ||||
loaddoc(b'bundlespec'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONCEPTS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'color'], | ||
_(b"Colorizing Outputs"), | ||||
loaddoc(b'color'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_OUTPUT, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"config", b"hgrc"], | ||
_(b"Configuration Files"), | ||||
loaddoc(b'config'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'deprecated'], | ||
_(b"Deprecated Features"), | ||||
loaddoc(b'deprecated'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_MISC, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"dates"], | ||
_(b"Date Formats"), | ||||
loaddoc(b'dates'), | ||||
TOPIC_CATEGORY_OUTPUT, | ||||
), | ||||
( | ||||
[b"flags"], | ||||
_(b"Command-line flags"), | ||||
loaddoc(b'flags'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"patterns"], | ||
_(b"File Name Patterns"), | ||||
loaddoc(b'patterns'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_IDS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'environment', b'env'], | ||
_(b'Environment Variables'), | ||||
loaddoc(b'environment'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [ | ||
b'revisions', | ||||
b'revs', | ||||
b'revsets', | ||||
b'revset', | ||||
b'multirevs', | ||||
b'mrevs', | ||||
], | ||||
_(b'Specifying Revisions'), | ||||
loaddoc(b'revisions'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_IDS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'filesets', b'fileset'], | ||
_(b"Specifying File Sets"), | ||||
loaddoc(b'filesets'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_IDS, | ||
), | ||||
( | ||||
Augie Fackler
|
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
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'templating', b'templates', b'template', b'style'], | ||
_(b'Template Usage'), | ||||
loaddoc(b'templates'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_OUTPUT, | ||
), | ||||
Augie Fackler
|
r43347 | ([b'urls'], _(b'URL Paths'), loaddoc(b'urls'), TOPIC_CATEGORY_IDS), | ||
Augie Fackler
|
r43346 | ( | ||
Augie Fackler
|
r43347 | [b"extensions"], | ||
_(b"Using Additional Features"), | ||||
Augie Fackler
|
r43346 | extshelp, | ||
TOPIC_CATEGORY_CONFIG, | ||||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"subrepos", b"subrepo"], | ||
_(b"Subrepositories"), | ||||
loaddoc(b'subrepos'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONCEPTS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"hgweb"], | ||
_(b"Configuring hgweb"), | ||||
loaddoc(b'hgweb'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"glossary"], | ||
_(b"Glossary"), | ||||
loaddoc(b'glossary'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONCEPTS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"hgignore", b"ignore"], | ||
_(b"Syntax for Mercurial Ignore Files"), | ||||
loaddoc(b'hgignore'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_IDS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b"phases"], | ||
_(b"Working with Phases"), | ||||
loaddoc(b'phases'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONCEPTS, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'scripting'], | ||
_(b'Using Mercurial from scripts and automation'), | ||||
loaddoc(b'scripting'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_MISC, | ||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'internals'], | ||
_(b"Technical implementation topics"), | ||||
Augie Fackler
|
r43346 | internalshelp, | ||
TOPIC_CATEGORY_MISC, | ||||
), | ||||
( | ||||
Augie Fackler
|
r43347 | [b'pager'], | ||
_(b"Pager Support"), | ||||
loaddoc(b'pager'), | ||||
Augie Fackler
|
r43346 | TOPIC_CATEGORY_CONFIG, | ||
), | ||||
] | ||||
) | ||||
Patrick Mezard
|
r12820 | |||
Gregory Szorc
|
r27379 | # Maps topics with sub-topics to a list of their sub-topics. | ||
subtopics = { | ||||
Augie Fackler
|
r43347 | b'internals': internalstable, | ||
Gregory Szorc
|
r27379 | } | ||
Patrick Mezard
|
r12820 | # Map topics to lists of callable taking the current topic help and | ||
# returning the updated version | ||||
Matt Mackall
|
r14318 | helphooks = {} | ||
Patrick Mezard
|
r12820 | |||
Augie Fackler
|
r43346 | |||
Patrick Mezard
|
r12820 | def addtopichook(topic, rewriter): | ||
helphooks.setdefault(topic, []).append(rewriter) | ||||
Patrick Mezard
|
r13593 | |||
Augie Fackler
|
r43346 | |||
Yuya Nishihara
|
r26414 | def makeitemsdoc(ui, topic, doc, marker, items, dedent=False): | ||
Patrick Mezard
|
r13593 | """Extract docstring from the items key to function mapping, build a | ||
timeless@mozdev.org
|
r26196 | single documentation block and use it to overwrite the marker in doc. | ||
Patrick Mezard
|
r13593 | """ | ||
entries = [] | ||||
for name in sorted(items): | ||||
Augie Fackler
|
r43347 | text = (pycompat.getdoc(items[name]) or b'').rstrip() | ||
Augie Fackler
|
r43346 | if not text or not ui.verbose and any(w in text for w in _exclkeywords): | ||
Patrick Mezard
|
r13593 | continue | ||
text = gettext(text) | ||||
Gregory Szorc
|
r24098 | if dedent: | ||
Augie Fackler
|
r32549 | # Abuse latin1 to use textwrap.dedent() on bytes. | ||
text = textwrap.dedent(text.decode('latin1')).encode('latin1') | ||||
Patrick Mezard
|
r13593 | lines = text.splitlines() | ||
"Yann E. MORIN"
|
r16250 | doclines = [(lines[0])] | ||
for l in lines[1:]: | ||||
# Stop once we find some Python doctest | ||||
Augie Fackler
|
r43347 | if l.strip().startswith(b'>>>'): | ||
"Yann E. MORIN"
|
r16250 | break | ||
Gregory Szorc
|
r24098 | if dedent: | ||
doclines.append(l.rstrip()) | ||||
else: | ||||
Augie Fackler
|
r43347 | doclines.append(b' ' + l.strip()) | ||
entries.append(b'\n'.join(doclines)) | ||||
entries = b'\n\n'.join(entries) | ||||
Patrick Mezard
|
r13593 | return doc.replace(marker, entries) | ||
Matt Mackall
|
r14318 | |||
Augie Fackler
|
r43346 | |||
Gregory Szorc
|
r24098 | def addtopicsymbols(topic, marker, symbols, dedent=False): | ||
Yuya Nishihara
|
r26414 | def add(ui, topic, doc): | ||
return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent) | ||||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r14318 | addtopichook(topic, add) | ||
Augie Fackler
|
r43346 | |||
addtopicsymbols( | ||||
Augie Fackler
|
r43347 | b'bundlespec', | ||
b'.. bundlecompressionmarker', | ||||
Augie Fackler
|
r43346 | compression.bundlecompressiontopics(), | ||
) | ||||
Augie Fackler
|
r43347 | addtopicsymbols(b'filesets', b'.. predicatesmarker', fileset.symbols) | ||
Augie Fackler
|
r43346 | addtopicsymbols( | ||
Augie Fackler
|
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
|
r43346 | ) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Valentin Gatien-Baron
|
r40472 | def inserttweakrc(ui, topic, doc): | ||
Augie Fackler
|
r43347 | marker = b'.. tweakdefaultsmarker' | ||
Valentin Gatien-Baron
|
r40472 | repl = uimod.tweakrc | ||
Augie Fackler
|
r43346 | |||
Valentin Gatien-Baron
|
r40472 | def sub(m): | ||
lines = [m.group(1) + s for s in repl.splitlines()] | ||||
Augie Fackler
|
r43347 | return b'\n'.join(lines) | ||
Augie Fackler
|
r43346 | |||
Valentin Gatien-Baron
|
r40472 | return re.sub(br'( *)%s' % re.escape(marker), sub, doc) | ||
Augie Fackler
|
r43346 | |||
Augie Fackler
|
r43347 | addtopichook(b'config', inserttweakrc) | ||
Valentin Gatien-Baron
|
r40472 | |||
Augie Fackler
|
r43346 | |||
def help_( | ||||
ui, | ||||
commands, | ||||
name, | ||||
unknowncmd=False, | ||||
full=True, | ||||
subtopic=None, | ||||
fullname=None, | ||||
**opts | ||||
): | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | ''' | ||
Generate the help for 'name' as unformatted restructured text. If | ||||
'name' is None, describe the commands available. | ||||
''' | ||||
Pulkit Goyal
|
r32143 | opts = pycompat.byteskwargs(opts) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Gregory Szorc
|
r27378 | def helpcmd(name, subtopic=None): | ||
Dan Villiom Podlaski Christiansen
|
r18746 | try: | ||
Augie Fackler
|
r43346 | aliases, entry = cmdutil.findcmd( | ||
name, commands.table, strict=unknowncmd | ||||
) | ||||
Gregory Szorc
|
r25660 | except error.AmbiguousCommand as inst: | ||
Martijn Pieters
|
r40299 | # py3 fix: except vars can't be used outside the scope of the | ||
Dan Villiom Podlaski Christiansen
|
r18746 | # except block, nor can be used inside a lambda. python issue4617 | ||
prefix = inst.args[0] | ||||
Yuya Nishihara
|
r36264 | select = lambda c: cmdutil.parsealiases(c)[0].startswith(prefix) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | rst = helplist(select) | ||
return rst | ||||
rst = [] | ||||
# check if it's an invalid alias and display its error if it is | ||||
Yuya Nishihara
|
r22160 | if getattr(entry[0], 'badalias', None): | ||
Augie Fackler
|
r43347 | rst.append(entry[0].badalias + b'\n') | ||
Yuya Nishihara
|
r22162 | if entry[0].unknowncmd: | ||
try: | ||||
rst.extend(helpextcmd(entry[0].cmdname)) | ||||
except error.UnknownCommand: | ||||
pass | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | return rst | ||
# synopsis | ||||
if len(entry) > 2: | ||||
Augie Fackler
|
r43347 | if entry[2].startswith(b'hg'): | ||
rst.append(b"%s\n" % entry[2]) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
Augie Fackler
|
r43347 | rst.append(b'hg %s %s\n' % (aliases[0], entry[2])) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
Augie Fackler
|
r43347 | rst.append(b'hg %s\n' % aliases[0]) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | # aliases | ||
if full and not ui.quiet and len(aliases) > 1: | ||||
Augie Fackler
|
r43347 | rst.append(_(b"\naliases: %s\n") % b', '.join(aliases[1:])) | ||
rst.append(b'\n') | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
# description | ||||
Yuya Nishihara
|
r32615 | doc = gettext(pycompat.getdoc(entry[0])) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | if not doc: | ||
Augie Fackler
|
r43347 | doc = _(b"(no help text available)") | ||
if util.safehasattr(entry[0], b'definition'): # aliased command | ||||
timeless
|
r28828 | source = entry[0].source | ||
Augie Fackler
|
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
|
r43346 | entry[0].definition[1:], | ||
doc, | ||||
source, | ||||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
Augie Fackler
|
r43347 | doc = _(b'alias for: hg %s\n\n%s\n\ndefined by: %s\n') % ( | ||
Augie Fackler
|
r43346 | entry[0].definition, | ||
doc, | ||||
source, | ||||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | doc = doc.splitlines(True) | ||
if ui.quiet or not full: | ||||
rst.append(doc[0]) | ||||
else: | ||||
rst.extend(doc) | ||||
Augie Fackler
|
r43347 | rst.append(b'\n') | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
# check if this command shadows a non-trivial (multi-line) | ||||
# extension help text | ||||
try: | ||||
mod = extensions.find(name) | ||||
Augie Fackler
|
r43347 | doc = gettext(pycompat.getdoc(mod)) or b'' | ||
if b'\n' in doc.strip(): | ||||
Augie Fackler
|
r43346 | msg = _( | ||
Augie Fackler
|
r43347 | b"(use 'hg help -e %s' to show help for " | ||
b"the %s extension)" | ||||
Augie Fackler
|
r43346 | ) % (name, name) | ||
Augie Fackler
|
r43347 | rst.append(b'\n%s\n' % msg) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | except KeyError: | ||
pass | ||||
# options | ||||
if not ui.quiet and entry[1]: | ||||
Valentin Gatien-Baron
|
r44777 | rst.append(optrst(_(b"options"), entry[1], ui.verbose, ui)) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
if ui.verbose: | ||||
Augie Fackler
|
r43346 | rst.append( | ||
Augie Fackler
|
r44787 | optrst( | ||
_(b"global options"), commands.globalopts, ui.verbose, ui | ||||
) | ||||
Augie Fackler
|
r43346 | ) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
if not ui.verbose: | ||||
if not full: | ||||
Augie Fackler
|
r43347 | rst.append(_(b"\n(use 'hg %s -h' to show more help)\n") % name) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | elif not ui.quiet: | ||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b'\n(some details hidden, use --verbose ' | ||
b'to show complete help)' | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
return rst | ||||
timeless
|
r27325 | def helplist(select=None, **opts): | ||
rdamazio@google.com
|
r40327 | # Category -> list of commands | ||
cats = {} | ||||
# Command -> short description | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | h = {} | ||
rdamazio@google.com
|
r40327 | # Command -> string showing synonyms | ||
syns = {} | ||||
Gregory Szorc
|
r43376 | for c, e in pycompat.iteritems(commands.table): | ||
Yuya Nishihara
|
r36264 | fs = cmdutil.parsealiases(c) | ||
f = fs[0] | ||||
Augie Fackler
|
r43347 | syns[f] = b', '.join(fs) | ||
rdamazio@google.com
|
r40327 | func = e[0] | ||
Rodrigo Damazio
|
r40331 | if select and not select(f): | ||
Dan Villiom Podlaski Christiansen
|
r18746 | continue | ||
rdamazio@google.com
|
r40327 | doc = pycompat.getdoc(func) | ||
rdamazio@google.com
|
r40450 | if filtercmd(ui, f, func, name, doc): | ||
Dan Villiom Podlaski Christiansen
|
r18746 | continue | ||
doc = gettext(doc) | ||||
if not doc: | ||||
Augie Fackler
|
r43347 | doc = _(b"(no help text available)") | ||
Dan Villiom Podlaski Christiansen
|
r18746 | h[f] = doc.splitlines()[0].rstrip() | ||
rdamazio@google.com
|
r40327 | |||
cat = getattr(func, 'helpcategory', None) or ( | ||||
Augie Fackler
|
r43346 | registrar.command.CATEGORY_NONE | ||
) | ||||
rdamazio@google.com
|
r40327 | cats.setdefault(cat, []).append(f) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
rst = [] | ||||
if not h: | ||||
if not ui.quiet: | ||||
Augie Fackler
|
r43347 | rst.append(_(b'no commands defined\n')) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | return rst | ||
rdamazio@google.com
|
r40327 | # Output top header. | ||
Dan Villiom Podlaski Christiansen
|
r18746 | if not ui.quiet: | ||
Augie Fackler
|
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
|
r18746 | else: | ||
Augie Fackler
|
r43347 | rst.append(_(b'list of commands:\n')) | ||
rdamazio@google.com
|
r40327 | |||
def appendcmds(cmds): | ||||
cmds = sorted(cmds) | ||||
for c in cmds: | ||||
if ui.verbose: | ||||
Augie Fackler
|
r43347 | rst.append(b" :%s: %s\n" % (syns[c], h[c])) | ||
rdamazio@google.com
|
r40327 | else: | ||
Augie Fackler
|
r43347 | rst.append(b' :%s: %s\n' % (c, h[c])) | ||
rdamazio@google.com
|
r40327 | |||
Augie Fackler
|
r43347 | if name in (b'shortlist', b'debug'): | ||
rdamazio@google.com
|
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
|
r43346 | ui.develwarn( | ||
Augie Fackler
|
r43347 | b'help categories missing from CATEGORY_ORDER: %s' | ||
Augie Fackler
|
r43346 | % missing_order | ||
) | ||||
rdamazio@google.com
|
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
|
r43347 | rst.append(b"\n%s:\n" % catname) | ||
rst.append(b"\n") | ||||
rdamazio@google.com
|
r40327 | appendcmds(catfns) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
timeless
|
r27325 | ex = opts.get | ||
Augie Fackler
|
r43906 | anyopts = ex('keyword') or not (ex('command') or ex('extension')) | ||
timeless
|
r27325 | if not name and anyopts: | ||
Augie Fackler
|
r43346 | exts = listexts( | ||
Augie Fackler
|
r43347 | _(b'enabled extensions:'), | ||
Augie Fackler
|
r43346 | extensions.enabled(), | ||
showdeprecated=ui.verbose, | ||||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | if exts: | ||
Augie Fackler
|
r43347 | rst.append(b'\n') | ||
Dan Villiom Podlaski Christiansen
|
r18746 | rst.extend(exts) | ||
Augie Fackler
|
r43347 | rst.append(_(b"\nadditional help topics:\n")) | ||
Rodrigo Damazio
|
r40328 | # Group commands by category. | ||
topiccats = {} | ||||
for topic in helptable: | ||||
names, header, doc = topic[0:3] | ||||
if len(topic) > 3 and topic[3]: | ||||
category = topic[3] | ||||
else: | ||||
category = TOPIC_CATEGORY_NONE | ||||
rdamazio@google.com
|
r40449 | topicname = names[0] | ||
if not filtertopic(ui, topicname): | ||||
topiccats.setdefault(category, []).append( | ||||
Augie Fackler
|
r43346 | (topicname, header) | ||
) | ||||
Rodrigo Damazio
|
r40328 | |||
# Check that all categories have an order. | ||||
missing_order = set(topiccats.keys()) - set(TOPIC_CATEGORY_ORDER) | ||||
if missing_order: | ||||
ui.develwarn( | ||||
Augie Fackler
|
r43347 | b'help categories missing from TOPIC_CATEGORY_ORDER: %s' | ||
Augie Fackler
|
r43346 | % missing_order | ||
) | ||||
Rodrigo Damazio
|
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
|
r43347 | rst.append(b"\n%s:\n" % catname) | ||
rst.append(b"\n") | ||||
Rodrigo Damazio
|
r40328 | for t, desc in topics: | ||
Augie Fackler
|
r43347 | rst.append(b" :%s: %s\n" % (t, desc)) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Matt Mackall
|
r22115 | if ui.quiet: | ||
pass | ||||
elif ui.verbose: | ||||
Augie Fackler
|
r43346 | rst.append( | ||
Augie Fackler
|
r43347 | b'\n%s\n' | ||
Augie Fackler
|
r44787 | % optrst( | ||
_(b"global options"), commands.globalopts, ui.verbose, ui | ||||
) | ||||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r43347 | if name == b'shortlist': | ||
Augie Fackler
|
r43346 | rst.append( | ||
Martin von Zweigbergk
|
r43387 | _(b"\n(use 'hg help' for the full list of commands)\n") | ||
Augie Fackler
|
r43346 | ) | ||
Matt Mackall
|
r22115 | else: | ||
Augie Fackler
|
r43347 | if name == b'shortlist': | ||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b"\n(use 'hg help' for the full list of commands " | ||
b"or 'hg -v' for details)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Matt Mackall
|
r22115 | elif name and not full: | ||
Augie Fackler
|
r43346 | rst.append( | ||
Martin von Zweigbergk
|
r43387 | _(b"\n(use 'hg help %s' to show the full help text)\n") | ||
Augie Fackler
|
r43346 | % name | ||
) | ||||
rdamazio@google.com
|
r40327 | elif name and syns and name in syns.keys(): | ||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b"\n(use 'hg help -v -e %s' to show built-in " | ||
b"aliases and global options)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
% name | ||||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b"\n(use 'hg help -v%s' to show built-in aliases " | ||
b"and global options)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r43347 | % (name and b" " + name or b"") | ||
Augie Fackler
|
r43346 | ) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | return rst | ||
Gregory Szorc
|
r27378 | def helptopic(name, subtopic=None): | ||
Gregory Szorc
|
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
|
r42585 | if not any(subtopic in s[0] for s in subtopics[name]): | ||
raise error.UnknownCommand(name) | ||||
Gregory Szorc
|
r27379 | |||
if not header: | ||||
Rodrigo Damazio
|
r40328 | for topic in helptable: | ||
names, header, doc = topic[0:3] | ||||
Gregory Szorc
|
r27379 | if name in names: | ||
break | ||||
else: | ||||
raise error.UnknownCommand(name) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Dan Villiom Podlaski Christiansen
|
r18748 | rst = [minirst.section(header)] | ||
Dan Villiom Podlaski Christiansen
|
r18746 | # description | ||
if not doc: | ||||
Augie Fackler
|
r43347 | rst.append(b" %s\n" % _(b"(no help text available)")) | ||
Augie Fackler
|
r21796 | if callable(doc): | ||
Augie Fackler
|
r43347 | rst += [b" %s\n" % l for l in doc(ui).splitlines()] | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
if not ui.verbose: | ||||
Augie Fackler
|
r43346 | omitted = _( | ||
Augie Fackler
|
r43347 | b'(some details hidden, use --verbose' | ||
b' to show complete help)' | ||||
Augie Fackler
|
r43346 | ) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | indicateomitted(rst, omitted) | ||
try: | ||||
cmdutil.findcmd(name, commands.table) | ||||
Augie Fackler
|
r43346 | rst.append( | ||
Martin von Zweigbergk
|
r43387 | _(b"\nuse 'hg help -c %s' to see help for the %s command\n") | ||
Augie Fackler
|
r43346 | % (name, name) | ||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | except error.UnknownCommand: | ||
pass | ||||
return rst | ||||
Gregory Szorc
|
r27378 | def helpext(name, subtopic=None): | ||
Dan Villiom Podlaski Christiansen
|
r18746 | try: | ||
mod = extensions.find(name) | ||||
Augie Fackler
|
r43347 | doc = gettext(pycompat.getdoc(mod)) or _(b'no help text available') | ||
Dan Villiom Podlaski Christiansen
|
r18746 | except KeyError: | ||
mod = None | ||||
Gregory Szorc
|
r45145 | doc = extensions.disabled_help(name) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | if not doc: | ||
raise error.UnknownCommand(name) | ||||
Augie Fackler
|
r43347 | if b'\n' not in doc: | ||
head, tail = doc, b"" | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
Augie Fackler
|
r43347 | head, tail = doc.split(b'\n', 1) | ||
rst = [_(b'%s extension - %s\n\n') % (name.rpartition(b'.')[-1], head)] | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | if tail: | ||
rst.extend(tail.splitlines(True)) | ||||
Augie Fackler
|
r43347 | rst.append(b'\n') | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
if not ui.verbose: | ||||
Augie Fackler
|
r43346 | omitted = _( | ||
Augie Fackler
|
r43347 | b'(some details hidden, use --verbose' | ||
b' to show complete help)' | ||||
Augie Fackler
|
r43346 | ) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | indicateomitted(rst, omitted) | ||
if mod: | ||||
try: | ||||
ct = mod.cmdtable | ||||
except AttributeError: | ||||
ct = {} | ||||
Augie Fackler
|
r43347 | modcmds = {c.partition(b'|')[0] for c in ct} | ||
Dan Villiom Podlaski Christiansen
|
r18746 | rst.extend(helplist(modcmds.__contains__)) | ||
else: | ||||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b"(use 'hg help extensions' for information on enabling" | ||
b" extensions)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | return rst | ||
Gregory Szorc
|
r27378 | def helpextcmd(name, subtopic=None): | ||
Augie Fackler
|
r43346 | cmd, ext, doc = extensions.disabledcmd( | ||
Augie Fackler
|
r43347 | ui, name, ui.configbool(b'ui', b'strict') | ||
Augie Fackler
|
r43346 | ) | ||
Yuya Nishihara
|
r37996 | doc = doc.splitlines()[0] | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Augie Fackler
|
r43346 | rst = listexts( | ||
Martin von Zweigbergk
|
r43387 | _(b"'%s' is provided by the following extension:") % cmd, | ||
Augie Fackler
|
r43346 | {ext: doc}, | ||
indent=4, | ||||
showdeprecated=True, | ||||
) | ||||
Augie Fackler
|
r43347 | rst.append(b'\n') | ||
Augie Fackler
|
r43346 | rst.append( | ||
_( | ||||
Augie Fackler
|
r43347 | b"(use 'hg help extensions' for information on enabling " | ||
b"extensions)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | return rst | ||
rst = [] | ||||
Augie Fackler
|
r43347 | kw = opts.get(b'keyword') | ||
timeless
|
r27325 | if kw or name is None and any(opts[o] for o in opts): | ||
Augie Fackler
|
r43347 | matches = topicmatch(ui, commands, name or b'') | ||
timeless@mozdev.org
|
r26238 | helpareas = [] | ||
Augie Fackler
|
r43347 | if opts.get(b'extension'): | ||
helpareas += [(b'extensions', _(b'Extensions'))] | ||||
if opts.get(b'command'): | ||||
helpareas += [(b'commands', _(b'Commands'))] | ||||
timeless@mozdev.org
|
r26238 | if not helpareas: | ||
Augie Fackler
|
r43346 | helpareas = [ | ||
Augie Fackler
|
r43347 | (b'topics', _(b'Topics')), | ||
(b'commands', _(b'Commands')), | ||||
(b'extensions', _(b'Extensions')), | ||||
(b'extensioncommands', _(b'Extension Commands')), | ||||
Augie Fackler
|
r43346 | ] | ||
timeless@mozdev.org
|
r26238 | for t, title in helpareas: | ||
Dan Villiom Podlaski Christiansen
|
r18746 | if matches[t]: | ||
Augie Fackler
|
r43347 | rst.append(b'%s:\n\n' % title) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | rst.extend(minirst.maketable(sorted(matches[t]), 1)) | ||
Augie Fackler
|
r43347 | rst.append(b'\n') | ||
Pierre-Yves David
|
r21288 | if not rst: | ||
Augie Fackler
|
r43347 | msg = _(b'no matches') | ||
hint = _(b"try 'hg help' for a list of topics") | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg, hint=hint) | ||
Augie Fackler
|
r43347 | elif name and name != b'shortlist': | ||
timeless@mozdev.org
|
r26238 | queries = [] | ||
Dan Villiom Podlaski Christiansen
|
r18746 | if unknowncmd: | ||
timeless@mozdev.org
|
r26238 | queries += [helpextcmd] | ||
Augie Fackler
|
r43347 | if opts.get(b'extension'): | ||
timeless@mozdev.org
|
r26238 | queries += [helpext] | ||
Augie Fackler
|
r43347 | if opts.get(b'command'): | ||
timeless@mozdev.org
|
r26238 | queries += [helpcmd] | ||
if not queries: | ||||
Dan Villiom Podlaski Christiansen
|
r18746 | queries = (helptopic, helpcmd, helpext, helpextcmd) | ||
for f in queries: | ||||
try: | ||||
Gregory Szorc
|
r27378 | rst = f(name, subtopic) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | break | ||
Pierre-Yves David
|
r21289 | except error.UnknownCommand: | ||
pass | ||||
else: | ||||
if unknowncmd: | ||||
raise error.UnknownCommand(name) | ||||
else: | ||||
Nathan Goldbaum
|
r42586 | if fullname: | ||
formatname = fullname | ||||
else: | ||||
formatname = name | ||||
if subtopic: | ||||
hintname = subtopic | ||||
else: | ||||
hintname = name | ||||
Augie Fackler
|
r43347 | msg = _(b'no such help topic: %s') % formatname | ||
hint = _(b"try 'hg help --keyword %s'") % hintname | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg, hint=hint) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | else: | ||
# program name | ||||
if not ui.quiet: | ||||
Augie Fackler
|
r43347 | rst = [_(b"Mercurial Distributed SCM\n"), b'\n'] | ||
Augie Fackler
|
r32547 | rst.extend(helplist(None, **pycompat.strkwargs(opts))) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | |||
Augie Fackler
|
r43347 | return b''.join(rst) | ||
Augie Fackler
|
r31059 | |||
Augie Fackler
|
r43346 | |||
def formattedhelp( | ||||
ui, commands, fullname, keep=None, unknowncmd=False, full=True, **opts | ||||
): | ||||
Augie Fackler
|
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
|
r31265 | else: | ||
Augie Fackler
|
r43346 | keep = list(keep) # make a copy so we can mutate this later | ||
Yuya Nishihara
|
r39375 | |||
# <fullname> := <name>[.<subtopic][.<section>] | ||||
name = subtopic = section = None | ||||
if fullname is not None: | ||||
Augie Fackler
|
r43347 | nameparts = fullname.split(b'.') | ||
Yuya Nishihara
|
r39375 | name = nameparts.pop(0) | ||
if nameparts and name in subtopics: | ||||
subtopic = nameparts.pop(0) | ||||
if nameparts: | ||||
Augie Fackler
|
r43347 | section = encoding.lower(b'.'.join(nameparts)) | ||
Yuya Nishihara
|
r39375 | |||
Augie Fackler
|
r43347 | textwidth = ui.configint(b'ui', b'textwidth') | ||
Augie Fackler
|
r31059 | termwidth = ui.termwidth() - 2 | ||
if textwidth <= 0 or termwidth < textwidth: | ||||
textwidth = termwidth | ||||
Augie Fackler
|
r43346 | text = help_( | ||
ui, | ||||
commands, | ||||
name, | ||||
fullname=fullname, | ||||
subtopic=subtopic, | ||||
unknowncmd=unknowncmd, | ||||
full=full, | ||||
**opts | ||||
) | ||||
Augie Fackler
|
r31059 | |||
Yuya Nishihara
|
r39344 | blocks, pruned = minirst.parse(text, keep=keep) | ||
Augie Fackler
|
r43347 | if b'verbose' in pruned: | ||
keep.append(b'omitted') | ||||
Augie Fackler
|
r31059 | else: | ||
Augie Fackler
|
r43347 | keep.append(b'notomitted') | ||
Yuya Nishihara
|
r39344 | blocks, pruned = minirst.parse(text, keep=keep) | ||
if section: | ||||
blocks = minirst.filtersections(blocks, section) | ||||
Yuya Nishihara
|
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): | ||||
Augie Fackler
|
r43347 | raise error.Abort(_(b"help section not found: %s") % fullname) | ||
Yuya Nishihara
|
r39345 | |||
Yuya Nishihara
|
r39344 | return minirst.formatplain(blocks, textwidth) | ||