Add unknown_case_counter/src/unknown_case_counter/cli.py
This commit is contained in:
parent
b373f2616e
commit
586dc6d1b2
1 changed files with 37 additions and 0 deletions
37
unknown_case_counter/src/unknown_case_counter/cli.py
Normal file
37
unknown_case_counter/src/unknown_case_counter/cli.py
Normal file
|
|
@ -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()
|
||||
Loading…
Reference in a new issue