Skip to content

Commit 6385a52

Browse files
committed
cli - show config message only in debug mode
1 parent 3af7fe5 commit 6385a52

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Not yet released
55
^^^^^^^^^^^^^^^^
66
**release date:** TBA
77

8+
* [CLI] show the message about the config file only with the ``--debug`` option.
89
* Relax the ``platformdirs`` dependency requirement to ``>= 3``
910

1011
2.2.0

subliminal/cli.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,18 @@ def convert(self, value: str, param: click.Parameter | None, ctx: click.Context
118118
def configure(ctx: click.Context, param: click.Parameter | None, filename: str | os.PathLike) -> None:
119119
"""Read a configuration file."""
120120
filename = pathlib.Path(filename).expanduser()
121+
msg = ''
121122
toml_dict = {}
122123
if filename.is_file():
123124
try:
124125
with open(filename, 'rb') as f:
125126
toml_dict = tomli.load(f)
126127
except tomli.TOMLDecodeError:
127128
msg = f'Cannot read the configuration file at {filename}'
128-
click.echo(msg)
129129
else:
130130
msg = f'Using configuration file at {filename}'
131-
click.echo(msg)
132131
else:
133132
msg = 'Not using any configuration file.'
134-
click.echo(msg)
135133

136134
options = {}
137135

@@ -148,7 +146,11 @@ def configure(ctx: click.Context, param: click.Parameter | None, filename: str |
148146
providers_dict = toml_dict.setdefault('provider', {})
149147
refiners_dict = toml_dict.setdefault('refiner', {})
150148

151-
ctx.obj = {'provider_configs': providers_dict, 'refiner_configs': refiners_dict}
149+
ctx.obj = {
150+
'__config__': {'dict': toml_dict, 'debug_message': msg},
151+
'provider_configs': providers_dict,
152+
'refiner_configs': refiners_dict,
153+
}
152154
ctx.default_map = options
153155

154156

@@ -254,6 +256,9 @@ def subliminal(
254256
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
255257
logging.getLogger('subliminal').addHandler(handler)
256258
logging.getLogger('subliminal').setLevel(logging.DEBUG)
259+
# log about the config file
260+
msg = ctx.obj['__config__']['debug_message']
261+
logger.info(msg)
257262

258263
ctx.obj['debug'] = debug
259264
# provider configs

0 commit comments

Comments
 (0)