Skip to content

Commit 2952812

Browse files
author
Hugo Osvaldo Barrera
committed
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).
1 parent c254b4a commit 2952812

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/system/cli/test_discover.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,45 @@ def __init__(self, require_collection, **kw):
239239
assert (
240240
"One or more storages don't support `collections = null`." in result.output
241241
)
242+
243+
244+
def test_showconfig(tmpdir, runner):
245+
runner.write_with_general(
246+
dedent(
247+
"""
248+
[storage foo]
249+
type = "filesystem"
250+
path = "{0}/foo/"
251+
fileext = ".txt"
252+
253+
[storage bar]
254+
type = "filesystem"
255+
path = "{0}/bar/"
256+
fileext = ".txt"
257+
258+
[pair foobar]
259+
a = "foo"
260+
b = "bar"
261+
collections = ["from a"]
262+
"""
263+
).format(str(tmpdir))
264+
)
265+
266+
result = runner.invoke(["showconfig"])
267+
assert not result.exception
268+
assert json.loads(result.output) == {
269+
"storages": [
270+
{
271+
"type": "filesystem",
272+
"path": f"{tmpdir}/foo/",
273+
"fileext": ".txt",
274+
"instance_name": "foo",
275+
},
276+
{
277+
"type": "filesystem",
278+
"path": f"{tmpdir}/bar/",
279+
"fileext": ".txt",
280+
"instance_name": "bar",
281+
},
282+
]
283+
}

vdirsyncer/cli/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functools
2+
import json
23
import logging
34
import sys
45

@@ -275,3 +276,16 @@ def repair(ctx, collection, repair_unsafe_uid):
275276
)
276277
click.confirm("Do you want to continue?", abort=True)
277278
repair_collection(ctx.config, collection, repair_unsafe_uid=repair_unsafe_uid)
279+
280+
281+
@app.command()
282+
@pass_context
283+
@catch_errors
284+
def showconfig(ctx: AppContext):
285+
"""Show the current configuration.
286+
287+
This is mostly intended to be used by scripts or other integrations.
288+
If you need additional information in this dump, please reach out.
289+
"""
290+
config = {"storages": list(ctx.config.storages.values())}
291+
click.echo(json.dumps(config, indent=2))

0 commit comments

Comments
 (0)