Add a --config option.

This commit is contained in:
Lucas Hoffmann 2016-04-07 10:31:07 +02:00
parent 69b88dd0c0
commit 10cc4b1a16
3 changed files with 9 additions and 5 deletions

View file

@ -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
=============

View file

@ -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

View file

@ -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',