diff --git a/src/reader/_cli.py b/src/reader/_cli.py index 082c1d16..282e4431 100644 --- a/src/reader/_cli.py +++ b/src/reader/_cli.py @@ -122,13 +122,12 @@ def wrapper(*args, **kwargs): def config_option(*args, **kwargs): def callback(ctx, param, value): - # TODO: the default file is allowed to not exist, a user specified file must exist + config_path = value if value is not None else get_default_config_path() try: - with open(value) as file: + with open(config_path) as file: config = make_reader_config(yaml.safe_load(file)) - except FileNotFoundError as e: - if value != param.default: - raise click.BadParameter(str(e), ctx=ctx, param=param) from None + except FileNotFoundError: + assert value is None config = make_reader_config({}) ctx.default_map = config['cli'].get('defaults', {}) @@ -136,17 +135,14 @@ def callback(ctx, param, value): ctx.obj = config return config - def inner(fn): - return click.option( - *args, - type=click.Path(dir_okay=False), - callback=callback, - is_eager=True, - expose_value=False, - **kwargs, - )(fn) - - return inner + return click.option( + *args, + type=click.Path(exists=True, dir_okay=False), + callback=callback, + is_eager=True, + expose_value=False, + **kwargs, + ) def pass_reader(fn): @@ -166,7 +162,6 @@ def wrapper(*args, **kwargs): '--db', type=click.Path(dir_okay=False), envvar=reader._DB_ENVVAR, - show_default=True, help=f"Path to the reader database. [default: {get_default_db_path()}]", ) @click.option( @@ -184,9 +179,7 @@ def wrapper(*args, **kwargs): @config_option( '--config', envvar=reader._CONFIG_ENVVAR, - help="Path to the reader config.", - default=get_default_config_path(), - show_default=True, + help=f"Path to the reader config. [default: {get_default_config_path()}]", ) @click.option( '--feed-root', diff --git a/tests/test_bench.py b/tests/test_bench.py index 4633edc3..443aa8c6 100644 --- a/tests/test_bench.py +++ b/tests/test_bench.py @@ -5,6 +5,7 @@ from click.testing import CliRunner from reader import make_reader +from test_cli import patch_app_dir from test_reader_filter import setup_reader_for_tags