Skip to content

Commit

Permalink
Add a --config-file option.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucc committed Apr 7, 2016
1 parent 69b88dd commit 4f8ed93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions vdirsyncer/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ 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
'''
_check_python2()
from .config import load_config

if not ctx.config:
ctx.config = load_config()
ctx.config = load_config(config)

main = app

Expand Down
7 changes: 4 additions & 3 deletions vdirsyncer/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4f8ed93

Please sign in to comment.