diff --git a/HISTORY.rst b/HISTORY.rst index 25b3f62a..ea24935e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,6 +5,7 @@ Not yet released ^^^^^^^^^^^^^^^^ **release date:** TBA +* [CLI] show the message about the config file only with the ``--debug`` option. * Relax the ``platformdirs`` dependency requirement to ``>= 3`` 2.2.0 diff --git a/subliminal/cli.py b/subliminal/cli.py index 04c7042b..0139c55c 100644 --- a/subliminal/cli.py +++ b/subliminal/cli.py @@ -118,6 +118,7 @@ def convert(self, value: str, param: click.Parameter | None, ctx: click.Context def configure(ctx: click.Context, param: click.Parameter | None, filename: str | os.PathLike) -> None: """Read a configuration file.""" filename = pathlib.Path(filename).expanduser() + msg = '' toml_dict = {} if filename.is_file(): try: @@ -125,13 +126,10 @@ def configure(ctx: click.Context, param: click.Parameter | None, filename: str | toml_dict = tomli.load(f) except tomli.TOMLDecodeError: msg = f'Cannot read the configuration file at {filename}' - click.echo(msg) else: msg = f'Using configuration file at {filename}' - click.echo(msg) else: msg = 'Not using any configuration file.' - click.echo(msg) options = {} @@ -148,7 +146,11 @@ def configure(ctx: click.Context, param: click.Parameter | None, filename: str | providers_dict = toml_dict.setdefault('provider', {}) refiners_dict = toml_dict.setdefault('refiner', {}) - ctx.obj = {'provider_configs': providers_dict, 'refiner_configs': refiners_dict} + ctx.obj = { + '__config__': {'dict': toml_dict, 'debug_message': msg}, + 'provider_configs': providers_dict, + 'refiner_configs': refiners_dict, + } ctx.default_map = options @@ -254,6 +256,9 @@ def subliminal( handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) logging.getLogger('subliminal').addHandler(handler) logging.getLogger('subliminal').setLevel(logging.DEBUG) + # log about the config file + msg = ctx.obj['__config__']['debug_message'] + logger.info(msg) ctx.obj['debug'] = debug # provider configs