changeset 34993:625d5ebce066

templatekw: add verbosity keyword to select template by -q/-v/--debug flag This can be used in conjunction with the ifeq() function.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 21 Oct 2017 17:46:41 +0900
parents e2fc6cec0eff
children 602c168c0207
files mercurial/templatekw.py tests/test-command-template.t
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sat Oct 21 17:31:13 2017 +0900
+++ b/mercurial/templatekw.py	Sat Oct 21 17:46:41 2017 +0900
@@ -885,6 +885,19 @@
     return showlist('instability', args['ctx'].instabilities(), args,
                     plural='instabilities')
 
+@templatekeyword('verbosity')
+def showverbosity(ui, **args):
+    """String. The current output verbosity in 'debug', 'quiet', 'verbose',
+    or ''."""
+    # see cmdutil.changeset_templater for priority of these flags
+    if ui.debugflag:
+        return 'debug'
+    elif ui.quiet:
+        return 'quiet'
+    elif ui.verbose:
+        return 'verbose'
+    return ''
+
 def loadkeyword(ui, extname, registrarobj):
     """Load template keyword from specified registrarobj
     """
--- a/tests/test-command-template.t	Sat Oct 21 17:31:13 2017 +0900
+++ b/tests/test-command-template.t	Sat Oct 21 17:46:41 2017 +0900
@@ -2876,6 +2876,17 @@
   @@ -0,0 +1,1 @@
   +second
 
+ui verbosity:
+
+  $ hg log -l1 -T '{verbosity}\n'
+  
+  $ hg log -l1 -T '{verbosity}\n' --debug
+  debug
+  $ hg log -l1 -T '{verbosity}\n' --quiet
+  quiet
+  $ hg log -l1 -T '{verbosity}\n' --verbose
+  verbose
+
   $ cd ..