D564: help: allow containers to be gated by configs
quark (Jun Wu)
phabricator at mercurial-scm.org
Wed Aug 30 00:05:19 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Previously, `.. container:: verbose` and platform-dependent names like
`windows`, `plan9` could be used to make conditional help text. This patch
adds the special `config:section.name=(true|false)` syntax so we can also
control help output by using configs.
This could be useful for documenting experimental features.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D564
AFFECTED FILES
mercurial/help.py
mercurial/minirst.py
tests/test-help.t
CHANGE DETAILS
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -435,6 +435,35 @@
--pager TYPE when to paginate (boolean, always, auto, or never)
(default: auto)
+Help depending on boolean config options
+
+ $ cat > $TESTTMP/myext.py << EOF
+ > """test help text with conditional configs
+ > .. container:: config:commands.update.requiredest=true
+ >
+ > This shows up when commands.update.requiredest is set to True.
+ >
+ > .. container:: config:commands.update.requiredest=false
+ >
+ > This shows up when commands.update.requiredest is set to False.
+ > """
+ > EOF
+
+ $ hg help -e myext --config extensions.myext=$TESTTMP/myext.py
+ myext extension - test help text with conditional configs
+
+ This shows up when commands.update.requiredest is set to False.
+
+ no commands defined
+
+ $ hg help -e myext --config extensions.myext=$TESTTMP/myext.py \
+ > --config commands.update.requiredest=1
+ myext extension - test help text with conditional configs
+
+ This shows up when commands.update.requiredest is set to True.
+
+ no commands defined
+
Test the textwidth config option
$ hg root -h --config ui.textwidth=50
diff --git a/mercurial/minirst.py b/mercurial/minirst.py
--- a/mercurial/minirst.py
+++ b/mercurial/minirst.py
@@ -267,10 +267,12 @@
indent = blocks[i]['indent']
adjustment = blocks[i + 1]['indent'] - indent
containertype = blocks[i]['lines'][0][15:]
- prune = True
- for c in keep:
- if c in containertype.split('.'):
- prune = False
+ prune = (containertype not in keep)
+ if prune and ':' not in containertype:
+ for c in keep:
+ if c in containertype.split('.'):
+ prune = False
+ break
if prune:
pruned.append(containertype)
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -9,6 +9,7 @@
import itertools
import os
+import re
import textwrap
from .i18n import (
@@ -654,6 +655,12 @@
text = help_(ui, commands, name,
subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts)
+ # Boolean configs, ex. "container:: configbool:experimental.foo"
+ configs = re.findall('(config:([^.]*)\.([\S]*)=(true|false))', text)
+ for fullname, cfgsection, cfgname, cfgvalue in set(configs):
+ if ui.configbool(cfgsection, cfgname) == (cfgvalue == 'true'):
+ keep.append(fullname)
+
formatted, pruned = minirst.format(text, textwidth, keep=keep,
section=section)
To: quark, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list