diff --git a/tests/cli/test_main.py b/tests/cli/test_sync.py similarity index 97% rename from tests/cli/test_main.py rename to tests/cli/test_sync.py index 1feaad8..5a801ed 100644 --- a/tests/cli/test_main.py +++ b/tests/cli/test_sync.py @@ -408,3 +408,12 @@ def test_unknown_storage(tmpdir, runner, existing, missing): "These are the configured storages: ['{existing}']" .format(missing=missing, existing=existing) ) in result.output + + +@pytest.mark.parametrize('cmd', ['sync', 'metasync']) +def test_no_configured_pairs(tmpdir, runner, cmd): + runner.write_with_general('') + + result = runner.invoke([cmd]) + assert result.output == 'critical: Nothing to do.\n' + assert result.exception.code == 5 diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index d5b57a9..97d4800 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -459,8 +459,17 @@ class WorkerQueue(object): assert self._workers or not self._queue.unfinished_tasks ui_worker = click_threading.UiWorker() self._shutdown_handlers.append(ui_worker.shutdown) + _echo = click.echo + with ui_worker.patch_click(): yield + + if not self._workers: + # Ugly hack, needed because ui_worker is not running. + click.echo = _echo + cli_logger.critical('Nothing to do.') + sys.exit(5) + ui_worker.run() self._queue.join() for worker in self._workers: