Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/cli.py
Show All 22 Lines | |||||
DEFAULT_CONFIG: Dict[str, Any] = { | DEFAULT_CONFIG: Dict[str, Any] = { | ||||
"web-api": { | "web-api": { | ||||
"url": "https://archive.softwareheritage.org/api/1/", | "url": "https://archive.softwareheritage.org/api/1/", | ||||
"auth-token": None, | "auth-token": None, | ||||
} | } | ||||
} | } | ||||
def parse_url(url): | |||||
"""CLI-specific helper to 'autocomplete' the provided url.""" | |||||
if not url.startswith("https://"): | |||||
url = "https://" + url | |||||
if not url.endswith("/"): | |||||
url += "/" | |||||
return url | |||||
@swh_cli_group.group(name="scanner", context_settings=CONTEXT_SETTINGS) | @swh_cli_group.group(name="scanner", context_settings=CONTEXT_SETTINGS) | ||||
@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=f"""YAML configuration file. If absent and cannot load the default one, | help=f"""YAML configuration file. If absent and cannot load the default one, | ||||
default parameters are used. | default parameters are used. | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
@click.pass_context | @click.pass_context | ||||
def scan(ctx, root_path, api_url, patterns, out_fmt, interactive): | def scan(ctx, root_path, api_url, patterns, out_fmt, interactive): | ||||
"""Scan a source code project to discover files and directories already | """Scan a source code project to discover files and directories already | ||||
present in the archive""" | present in the archive""" | ||||
from .scanner import scan | from .scanner import scan | ||||
config = ctx.obj["config"] | config = ctx.obj["config"] | ||||
if api_url: | if api_url: | ||||
config["web-api"]["url"] = parse_url(api_url) | if not api_url.endswith("/"): | ||||
api_url += "/" | |||||
config["web-api"]["url"] = api_url | |||||
scan(config, root_path, patterns, out_fmt, interactive) | scan(config, root_path, patterns, out_fmt, interactive) | ||||
def main(): | def main(): | ||||
return scanner(auto_envvar_prefix="SWH_SCANNER") | return scanner(auto_envvar_prefix="SWH_SCANNER") | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
main() | main() |