Add report_generator/src/report_generator/cli.py

This commit is contained in:
Mika 2026-01-29 16:23:28 +00:00
parent 339b75d473
commit 62fa3e2966

View file

@ -0,0 +1,60 @@
import argparse
import json
import os
from pathlib import Path
from datetime import datetime
from report_generator.core import generate_report
def main() -> None:
"""CLI entrypoint: loads drift metrics, invokes report generation, and stores the output."""
parser = argparse.ArgumentParser(description="Generate a CI drift analysis report.")
parser.add_argument(
"--input",
required=True,
help="Pfad zur JSON-Datei mit aggregierten Drift-Check-Ergebnissen.",
)
parser.add_argument(
"--threshold",
required=False,
type=float,
default=0.3,
help="WARN-Schwelle (Standard: 0.3).",
)
args = parser.parse_args()
input_path = Path(args.input)
if not input_path.exists() or not input_path.is_file():
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
# Load JSON with input validation
with input_path.open("r", encoding="utf-8") as f:
try:
data = json.load(f)
except json.JSONDecodeError as e:
raise ValueError(f"Ungültiges JSON-Format: {e}")
required_fields = ["warn_count", "total_runs"]
for field in required_fields:
if field not in data:
raise KeyError(f"Fehlendes Feld '{field}' in Eingabedatei.")
if not isinstance(data[field], int):
raise TypeError(f"Feld '{field}' muss vom Typ int sein, erhalten: {type(data[field])}.")
warn_count = data["warn_count"]
total_runs = data["total_runs"]
if total_runs <= 0:
raise ValueError("total_runs muss größer als 0 sein.")
threshold = args.threshold
report_path = generate_report(warn_count, total_runs, threshold)
# Optional: echo summary info
print(f"Bericht generiert: {report_path}")
if __name__ == "__main__":
main()