Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/cli.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# WARNING: do not import unnecessary things here to keep cli startup time under | # WARNING: do not import unnecessary things here to keep cli startup time under | ||||
# control | # control | ||||
import os | import os | ||||
from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
import click | import click | ||||
from importlib_metadata import version | |||||
import yaml | import yaml | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS | ||||
from swh.core.cli import swh as swh_cli_group | from swh.core.cli import swh as swh_cli_group | ||||
from .exceptions import DBError | from .exceptions import DBError | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
) | ) | ||||
@click.option( | @click.option( | ||||
"-C", | "-C", | ||||
"--config-file", | "--config-file", | ||||
default=None, | default=None, | ||||
type=click.Path(exists=False, dir_okay=False, path_type=str), | type=click.Path(exists=False, dir_okay=False, path_type=str), | ||||
help="""YAML configuration file""", | help="""YAML configuration file""", | ||||
) | ) | ||||
@click.version_option( | |||||
version=version("swh-scanner"), prog_name="swh-scanner", | |||||
) | |||||
@click.pass_context | @click.pass_context | ||||
def scanner(ctx, config_file: Optional[str]): | def scanner(ctx, config_file: Optional[str]): | ||||
env_config_path = os.environ.get(CONFIG_ENVVAR) | env_config_path = os.environ.get(CONFIG_ENVVAR) | ||||
# read_raw_config do not fail if file does not exist, so check it beforehand | # read_raw_config do not fail if file does not exist, so check it beforehand | ||||
# while enforcing loading priority | # while enforcing loading priority | ||||
if config_file: | if config_file: | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |