From 29528123a38d59184e9fa186438b84679cfeae5c Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Wed, 16 Jun 2021 19:03:50 +0200 Subject: [PATCH 1/2] Add a command to print the current config This is intended to be used by external tools and integrations (such as daemons which trigger `vdirsyncer` when there's a change in a collection). --- tests/system/cli/test_discover.py | 42 +++++++++++++++++++++++++++++++ vdirsyncer/cli/__init__.py | 14 +++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/system/cli/test_discover.py b/tests/system/cli/test_discover.py index fd76990..11083ef 100644 --- a/tests/system/cli/test_discover.py +++ b/tests/system/cli/test_discover.py @@ -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", + }, + ] + } diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 90fd44a..d1cb738 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -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)) From 6cebba0853f4fa31abca6ca0ba7428008c5227ad Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Thu, 17 Jun 2021 08:42:45 +0200 Subject: [PATCH 2/2] Add a changelog entry --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index cde27d6..e5a2fab 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ==============