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:: config:experimental.foo=true" + 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) 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/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