[PATCH 4 of 4] commands: add template support for config
Yuya Nishihara
yuya at tcha.org
Tue Aug 9 09:55:45 EDT 2016
On Mon, 08 Aug 2016 10:54:46 -0500, Mathias De Maré wrote:
> # 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 @@
value = str(value).replace('\n', '\\n')
'\n' should be escaped only in plain format.
> if v == section:
> ui.debug('%s: ' %
> ui.configsource(section, name, untrusted))
fm.condwrite(ui.debug, 'source', ...) ?
> - ui.write('%s=%s\n' % (sectname, value))
> + fm.startitem()
> + fm.write('section value', '%s=%s\n', sectname, value)
sectname isn't a section. I don't know the right word, but "name" would be
better.
> elif v == sectname:
> ui.debug('%s: ' %
> ui.configsource(section, name, untrusted))
> - ui.write(value, '\n')
> + fm.startitem()
> + fm.write('value', '%s\n', value)
fm.data(...=sectname) to include both name and value.
More information about the Mercurial-devel
mailing list