Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG9c6473d2038b: help: splitting the topics by category
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/help.py (41 lines) | |||
M | mercurial/hgweb/webcommands.py (3 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Rodrigo Damazio | Oct 12 2018, 11:57 AM |
# The order in which command categories will be displayed. | # The order in which command categories will be displayed. | ||||
# Extensions with custom categories should insert them into this list | # Extensions with custom categories should insert them into this list | ||||
# after/before the appropriate item, rather than replacing the list or | # after/before the appropriate item, rather than replacing the list or | ||||
# assuming absolute positions. | # assuming absolute positions. | ||||
CATEGORY_ORDER = [ | CATEGORY_ORDER = [ | ||||
CATEGORY_NONE, | CATEGORY_NONE, | ||||
] | ] | ||||
# Topic categories. | |||||
TOPIC_CATEGORY_NONE = _('Uncategorized topics') | |||||
# 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 = [ | |||||
TOPIC_CATEGORY_NONE, | |||||
] | |||||
def listexts(header, exts, indent=1, showdeprecated=False): | def listexts(header, exts, indent=1, showdeprecated=False): | ||||
'''return a text listing of the given extensions''' | '''return a text listing of the given extensions''' | ||||
rst = [] | rst = [] | ||||
if exts: | if exts: | ||||
for name, desc in sorted(exts.iteritems()): | for name, desc in sorted(exts.iteritems()): | ||||
if not showdeprecated and any(w in desc for w in _exclkeywords): | if not showdeprecated and any(w in desc for w in _exclkeywords): | ||||
continue | continue | ||||
rst.append('%s:%s: %s\n' % (' ' * indent, name, desc)) | rst.append('%s:%s: %s\n' % (' ' * indent, name, desc)) | ||||
kw = encoding.lower(kw) | kw = encoding.lower(kw) | ||||
def lowercontains(container): | def lowercontains(container): | ||||
return kw in encoding.lower(container) # translated in helptable | return kw in encoding.lower(container) # translated in helptable | ||||
results = {'topics': [], | results = {'topics': [], | ||||
'commands': [], | 'commands': [], | ||||
'extensions': [], | 'extensions': [], | ||||
'extensioncommands': [], | 'extensioncommands': [], | ||||
} | } | ||||
for names, header, doc in helptable: | for topic in helptable: | ||||
names, header, doc = topic[0:3] | |||||
# Old extensions may use a str as doc. | # Old extensions may use a str as doc. | ||||
if (sum(map(lowercontains, names)) | if (sum(map(lowercontains, names)) | ||||
or lowercontains(header) | or lowercontains(header) | ||||
or (callable(doc) and lowercontains(doc(ui)))): | or (callable(doc) and lowercontains(doc(ui)))): | ||||
results['topics'].append((names[0], header)) | results['topics'].append((names[0], header)) | ||||
for cmd, entry in commands.table.iteritems(): | for cmd, entry in commands.table.iteritems(): | ||||
if len(entry) == 3: | if len(entry) == 3: | ||||
summary = entry[2] | summary = entry[2] | ||||
ex = opts.get | ex = opts.get | ||||
anyopts = (ex(r'keyword') or not (ex(r'command') or ex(r'extension'))) | anyopts = (ex(r'keyword') or not (ex(r'command') or ex(r'extension'))) | ||||
if not name and anyopts: | if not name and anyopts: | ||||
exts = listexts(_('enabled extensions:'), extensions.enabled()) | exts = listexts(_('enabled extensions:'), extensions.enabled()) | ||||
if exts: | if exts: | ||||
rst.append('\n') | rst.append('\n') | ||||
rst.extend(exts) | rst.extend(exts) | ||||
rst.append(_("\nadditional help topics:\n\n")) | rst.append(_("\nadditional help topics:\n")) | ||||
topics = [] | topiccats = {} | ||||
for names, header, doc in helptable: | for topic in helptable: | ||||
topics.append((names[0], header)) | names, header, doc = topic[0:3] | ||||
if len(topic) > 3 and topic[3]: | |||||
category = topic[3] | |||||
else: | |||||
category = TOPIC_CATEGORY_NONE | |||||
topiccats.setdefault(category, []).append((names[0], header)) | |||||
for cat in TOPIC_CATEGORY_ORDER: | |||||
topics = topiccats.get(cat, []) | |||||
if topics: | |||||
if len(topiccats) > 1: | |||||
rst.append("\n%s:\n" % cat) | |||||
rst.append("\n") | |||||
for t, desc in topics: | for t, desc in topics: | ||||
rst.append(" :%s: %s\n" % (t, desc)) | rst.append(" :%s: %s\n" % (t, desc)) | ||||
if ui.quiet: | if ui.quiet: | ||||
pass | pass | ||||
elif ui.verbose: | elif ui.verbose: | ||||
rst.append('\n%s\n' % optrst(_("global options"), | rst.append('\n%s\n' % optrst(_("global options"), | ||||
commands.globalopts, ui.verbose)) | commands.globalopts, ui.verbose)) | ||||
if name == 'shortlist': | if name == 'shortlist': | ||||
rst.append(_("\n(use 'hg help' for the full list " | rst.append(_("\n(use 'hg help' for the full list " | ||||
# Look for sub-topic entry first. | # Look for sub-topic entry first. | ||||
header, doc = None, None | header, doc = None, None | ||||
if subtopic and name in subtopics: | if subtopic and name in subtopics: | ||||
for names, header, doc in subtopics[name]: | for names, header, doc in subtopics[name]: | ||||
if subtopic in names: | if subtopic in names: | ||||
break | break | ||||
if not header: | if not header: | ||||
for names, header, doc in helptable: | for topic in helptable: | ||||
names, header, doc = topic[0:3] | |||||
if name in names: | if name in names: | ||||
break | break | ||||
else: | else: | ||||
raise error.UnknownCommand(name) | raise error.UnknownCommand(name) | ||||
rst = [minirst.section(header)] | rst = [minirst.section(header)] | ||||
# description | # description |
The ``help`` template will be rendered when requesting help for a topic. | The ``help`` template will be rendered when requesting help for a topic. | ||||
``helptopics`` will be rendered for the index of help topics. | ``helptopics`` will be rendered for the index of help topics. | ||||
""" | """ | ||||
from .. import commands, help as helpmod # avoid cycle | from .. import commands, help as helpmod # avoid cycle | ||||
topicname = web.req.qsparams.get('node') | topicname = web.req.qsparams.get('node') | ||||
if not topicname: | if not topicname: | ||||
def topics(context): | def topics(context): | ||||
for entries, summary, _doc in helpmod.helptable: | for h in helpmod.helptable: | ||||
entries, summary, _doc = h[0:3] | |||||
yield {'topic': entries[0], 'summary': summary} | yield {'topic': entries[0], 'summary': summary} | ||||
early, other = [], [] | early, other = [], [] | ||||
primary = lambda s: s.partition('|')[0] | primary = lambda s: s.partition('|')[0] | ||||
for c, e in commands.table.iteritems(): | for c, e in commands.table.iteritems(): | ||||
doc = _getdoc(e) | doc = _getdoc(e) | ||||
if 'DEPRECATED' in doc or c.startswith('debug'): | if 'DEPRECATED' in doc or c.startswith('debug'): | ||||
continue | continue |