Patchwork D564: help: allow containers to be gated by configs

login
register
mail settings
Submitter phabricator
Date Aug. 30, 2017, 2:44 a.m.
Message ID <3c9d92a22cac91d93907bdd89bf3f43e@localhost.localdomain>
Download mbox | patch
Permalink /patch/23494/
State Not Applicable
Headers show

Comments

phabricator - Aug. 30, 2017, 2:44 a.m.
quark updated this revision to Diff 1423.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D564?vs=1414&id=1423

REVISION DETAIL
  https://phab.mercurial-scm.org/D564

AFFECTED FILES
  mercurial/help.py
  mercurial/minirst.py
  tests/test-help.t

CHANGE DETAILS




To: quark, #hg-reviewers
Cc: mercurial-devel

Patch

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:: 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)