#!/usr/bin/env python3
"""Decode a Make PATHS payload into one normalized repository path per line."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path

_SCRIPTS_DIR = Path(__file__).resolve().parent
if str(_SCRIPTS_DIR) not in sys.path:
    sys.path.insert(0, str(_SCRIPTS_DIR))
from _ci_paths import normalize_paths, path_values  # noqa: E402


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--file", type=Path, required=True)
    args = parser.parse_args()
    try:
        paths = normalize_paths(path_values(args.file.read_text(encoding="utf-8")))
    except (OSError, ValueError) as exc:
        parser.error(str(exc))
    print(*paths, sep="\n")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
