diff --git a/gate_v1_function/src/gate_v1_function/cli.py b/gate_v1_function/src/gate_v1_function/cli.py new file mode 100644 index 0000000..58a28d3 --- /dev/null +++ b/gate_v1_function/src/gate_v1_function/cli.py @@ -0,0 +1,68 @@ +import argparse +import json +import sys +from pathlib import Path + +from gate_v1_function.core import calculate_gate_decision + + +def main() -> None: + """CLI entry point for Gate v1 Decision Function. + + Parses CLI arguments and invokes calculate_gate_decision with given file paths. + Prints the resulting GateDecision (as JSON) to stdout. + """ + parser = argparse.ArgumentParser( + description="Compute gate decision based on delta summary and delta cases." + ) + parser.add_argument( + "--delta-summary", + required=True, + dest="delta_summary_path", + help="Path to delta_summary.json", + ) + parser.add_argument( + "--delta-cases", + required=True, + dest="delta_cases_path", + help="Path to delta_cases.csv", + ) + parser.add_argument( + "--whitelist", + required=False, + dest="unknown_whitelist_path", + help="Optional path to unknown_whitelist.json", + ) + + args = parser.parse_args() + + # Basic input validation + delta_summary_path = Path(args.delta_summary_path) + delta_cases_path = Path(args.delta_cases_path) + unknown_whitelist_path = (Path(args.unknown_whitelist_path) + if args.unknown_whitelist_path else None) + + for p in [delta_summary_path, delta_cases_path]: + if not p.exists(): + sys.stderr.write(f"Error: required file not found: {p}\n") + sys.exit(1) + + # Call core function + try: + decision = calculate_gate_decision( + str(delta_summary_path), str(delta_cases_path), + str(unknown_whitelist_path) if unknown_whitelist_path else None + ) + except Exception as exc: + sys.stderr.write(f"Error during gate calculation: {exc}\n") + sys.exit(2) + + # Output decision JSON + print(json.dumps({ + "decision": decision.decision, + "reasons": decision.reasons, + }, indent=2)) + + +if __name__ == "__main__": + main()