From 10cc4b1a163e990b8f966bd34f9cbeef505cb60e Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 7 Apr 2016 10:31:07 +0200 Subject: [PATCH] Add a --config option. --- CHANGELOG.rst | 2 ++ vdirsyncer/cli/__init__.py | 5 +++-- vdirsyncer/cli/config.py | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8f3e5a7..e37d957 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,8 @@ Version 0.10.0 - New storage types :storage:`google_calendar` and :storage:`google_contacts` have been added. +- New global command line option `--config`, to specify an alternative config + file. See :gh:`409`. Version 0.9.3 ============= diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 08e4157..7e2e249 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -50,9 +50,10 @@ def _check_python2(): @click_log.init('vdirsyncer') @click_log.simple_verbosity_option() @click.version_option(version=__version__) +@click.option('--config', '-c', metavar='FILE', help='Config file to use.') @pass_context @catch_errors -def app(ctx): +def app(ctx, config): ''' vdirsyncer -- synchronize calendars and contacts ''' @@ -60,7 +61,7 @@ def app(ctx): from .config import load_config if not ctx.config: - ctx.config = load_config() + ctx.config = load_config(config) main = app diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index e663973..08ee99b 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -79,9 +79,10 @@ def _validate_pair_section(pair_config): raise ValueError('Duplicate values in collections parameter.') -def load_config(): - fname = os.environ.get('VDIRSYNCER_CONFIG', None) - if not fname: +def load_config(fname=None): + if fname is None: + fname = os.environ.get('VDIRSYNCER_CONFIG', None) + if fname is None: fname = expand_path('~/.vdirsyncer/config') if not os.path.exists(fname): xdg_config_dir = os.environ.get('XDG_CONFIG_HOME',