Skip to content

Commit

Permalink
cli - show config message only in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Jun 26, 2024
1 parent 3af7fe5 commit 6385a52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions subliminal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,18 @@ 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:
with open(filename, 'rb') as f:
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 = {}

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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6385a52

Please sign in to comment.