diff --git a/unknown_case_counter/src/unknown_case_counter/cli.py b/unknown_case_counter/src/unknown_case_counter/cli.py new file mode 100644 index 0000000..9d117b9 --- /dev/null +++ b/unknown_case_counter/src/unknown_case_counter/cli.py @@ -0,0 +1,37 @@ +import argparse +import json +import sys +from pathlib import Path +from unknown_case_counter.core import count_unknown_reasons + +def _parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser( + description="Zählt Unknown-Fälle in Delta-Cases nach Ursache.", + ) + parser.add_argument( + "--input", + required=True, + help="Pfad zur CSV-Datei mit Delta-Cases.", + ) + return parser.parse_args() + +def main() -> None: + args = _parse_args() + input_path = Path(args.input) + + # CI-Ready: Validate input file type and existence + assert input_path.exists(), f"Input file not found: {input_path}" + assert input_path.is_file(), f"Input path is not a file: {input_path}" + + # Call the core function + try: + summary = count_unknown_reasons(str(input_path)) + except Exception as exc: + print(json.dumps({"error": str(exc)}), file=sys.stderr) + sys.exit(1) + + # Output as JSON to stdout + json.dump(summary, sys.stdout, indent=2, ensure_ascii=False) + +if __name__ == "__main__": + main()