Merge pull request #905 from pimutils/showconfig

Add a command to print the current config
This commit is contained in:
Hugo Osvaldo Barrera 2021-06-19 13:38:15 +02:00 committed by GitHub
commit 59b6e24795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 0 deletions

View file

@ -15,6 +15,9 @@ Version 0.19.0
- Add "description" and "order" as metadata. These fetch the CalDAV:
calendar-description, CardDAV:addressbook-description and apple-ns:calendar-order
properties.
- Add a new "showconfig" status. This prints *some* configuration values as
JSON. This is intended to be used by external tools and helpers that interact
with ``vdirsyncer``.
Version 0.18.0
==============

View file

@ -239,3 +239,45 @@ def test_collection_required(a_requires, b_requires, tmpdir, runner, monkeypatch
assert (
"One or more storages don't support `collections = null`." in result.output
)
def test_showconfig(tmpdir, runner):
runner.write_with_general(
dedent(
"""
[storage foo]
type = "filesystem"
path = "{0}/foo/"
fileext = ".txt"
[storage bar]
type = "filesystem"
path = "{0}/bar/"
fileext = ".txt"
[pair foobar]
a = "foo"
b = "bar"
collections = ["from a"]
"""
).format(str(tmpdir))
)
result = runner.invoke(["showconfig"])
assert not result.exception
assert json.loads(result.output) == {
"storages": [
{
"type": "filesystem",
"path": f"{tmpdir}/foo/",
"fileext": ".txt",
"instance_name": "foo",
},
{
"type": "filesystem",
"path": f"{tmpdir}/bar/",
"fileext": ".txt",
"instance_name": "bar",
},
]
}

View file

@ -1,4 +1,5 @@
import functools
import json
import logging
import sys
@ -275,3 +276,16 @@ def repair(ctx, collection, repair_unsafe_uid):
)
click.confirm("Do you want to continue?", abort=True)
repair_collection(ctx.config, collection, repair_unsafe_uid=repair_unsafe_uid)
@app.command()
@pass_context
@catch_errors
def showconfig(ctx: AppContext):
"""Show the current configuration.
This is mostly intended to be used by scripts or other integrations.
If you need additional information in this dump, please reach out.
"""
config = {"storages": list(ctx.config.storages.values())}
click.echo(json.dumps(config, indent=2))