[PATCH 4 of 4] commands: add template support for config
Mathias De Maré
mathias.demare at gmail.com
Mon Aug 8 15:54:46 UTC 2016
# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1470324689 -7200
# Thu Aug 04 17:31:29 2016 +0200
# Node ID c497d3c35883e43599d0a9f07f0894a582c4aede
# Parent 74056050d1bd9069f0dfaed861162ee65a77032d
commands: add template support for config
Example output:
hg config -Tjson ui.username
[
{
"value": "Mathias De Maré <mathias.demare at gmail.com>"
}
]
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1787,7 +1787,7 @@
[('u', 'untrusted', None, _('show untrusted configuration options')),
('e', 'edit', None, _('edit user config')),
('l', 'local', None, _('edit repository config')),
- ('g', 'global', None, _('edit global config'))],
+ ('g', 'global', None, _('edit global config'))] + formatteropts,
_('[-u] [NAME]...'),
optionalrepo=True)
def config(ui, repo, *values, **opts):
@@ -1848,6 +1848,7 @@
onerr=error.Abort, errprefix=_("edit failed"))
return
+ fm = ui.formatter('config', opts)
for f in scmutil.rcpath():
ui.debug('read config from: %s\n' % f)
untrusted = bool(opts.get('untrusted'))
@@ -1865,18 +1866,22 @@
if v == section:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
- ui.write('%s=%s\n' % (sectname, value))
+ fm.startitem()
+ fm.write('section value', '%s=%s\n', sectname, value)
matched = True
elif v == sectname:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
- ui.write(value, '\n')
+ fm.startitem()
+ fm.write('value', '%s\n', value)
matched = True
else:
ui.debug('%s: ' %
ui.configsource(section, name, untrusted))
- ui.write('%s=%s\n' % (sectname, value))
+ fm.startitem()
+ fm.write('section value', '%s=%s\n', sectname, value)
matched = True
+ fm.end()
if matched:
return 0
return 1
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -232,7 +232,7 @@
branches: active, closed, template
bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
cat: output, rev, decode, include, exclude
- config: untrusted, edit, local, global
+ config: untrusted, edit, local, global, template
copy: after, force, include, exclude, dry-run
debugancestor:
debugapplystreamclonebundle:
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -54,6 +54,18 @@
Section.KeY=Case Sensitive
Section.key=lower case
+ $ hg showconfig Section -Tjson
+ [
+ {
+ "section": "Section.KeY",
+ "value": "Case Sensitive"
+ },
+ {
+ "section": "Section.key",
+ "value": "lower case"
+ }
+ ]
+
Test "%unset"
$ cat >> $HGRCPATH <<EOF
More information about the Mercurial-devel
mailing list