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