From b7029b9148d08d7e0385b7f75621ebdabc139c4a Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 12 Feb 2026 11:16:22 +0000 Subject: [PATCH] Add log_enhancer/src/log_enhancer/cli.py --- log_enhancer/src/log_enhancer/cli.py | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 log_enhancer/src/log_enhancer/cli.py diff --git a/log_enhancer/src/log_enhancer/cli.py b/log_enhancer/src/log_enhancer/cli.py new file mode 100644 index 0000000..aa0cf4b --- /dev/null +++ b/log_enhancer/src/log_enhancer/cli.py @@ -0,0 +1,53 @@ +import argparse +import json +from pathlib import Path +from typing import List, Dict +import os + +from log_enhancer.core import enhance_log_entries + + +def _validate_file(path: Path, must_exist: bool = True) -> Path: + if must_exist and not path.exists(): + raise FileNotFoundError(f"Datei nicht gefunden: {path}") + if must_exist and not path.is_file(): + raise ValueError(f"Pfad ist keine Datei: {path}") + return path + + +def main() -> None: + parser = argparse.ArgumentParser( + description=( + "CLI-Tool zur Verbesserung von Logeinträgen durch Hinzufügen fehlender Artefaktinformationen." + ) + ) + parser.add_argument( + "--input", + required=True, + help="Pfad zur Eingabedatei mit Roh-Logdaten im JSON-Format." + ) + parser.add_argument( + "--output", + required=True, + help="Pfad zur Ausgabedatei für angereicherte Logs." + ) + + args = parser.parse_args() + + input_path = _validate_file(Path(args.input)) + output_path = Path(args.output) + + with input_path.open("r", encoding="utf-8") as f: + log_data: List[Dict] = json.load(f) + + assert isinstance(log_data, list), "Eingabedaten müssen eine Liste von Logeinträgen sein." + + enhanced_logs = enhance_log_entries(log_data) + + os.makedirs(output_path.parent, exist_ok=True) + with output_path.open("w", encoding="utf-8") as f: + json.dump(enhanced_logs, f, ensure_ascii=False, indent=2) + + +if __name__ == "__main__": + main()