Skip to content
Snippets Groups Projects
Verified Commit 9d325b82 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

search.cli: Unify configuration loading from environment variable

This aligns the behavior of the cli with the other swh modules'
cli (e.g. scheduler, deposit, ...).

Refs. swh/infra/sysadm-environment#5344
parent e2a471be
No related branches found
Tags v0.21.0
1 merge request!156search.cli: Unify configuration loading from environment variable
Pipeline #9723 passed
# Copyright (C) 2019-2020 The Software Heritage developers
# Copyright (C) 2019-2024 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -22,15 +22,26 @@ from swh.core.cli import swh as swh_cli_group
exists=True,
dir_okay=False,
),
help="Configuration file.",
help=(
"Configuration file. This has a higher priority than SWH_CONFIG_FILENAME "
"environment variable if set."
),
)
@click.pass_context
def search_cli_group(ctx, config_file):
"""Software Heritage Search tools."""
from os import environ
from swh.core import config
ctx.ensure_object(dict)
conf = config.read(config_file)
if config_file:
conf = config.read(config_file)
elif "SWH_CONFIG_FILENAME" in environ:
conf = config.load_from_envvar()
else:
raise ValueError("No configuration file set.")
ctx.obj["config"] = conf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment