File size: 852 Bytes
6364e69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import annotations

import json
from pathlib import Path
import typer

from doctrine.loader import RuleLoader
from doctrine.engine import PillarsEngine
from doctrine.audit import append_record

app = typer.Typer(help="Doctrine pillars engine CLI")


@app.command()
def check(text: str = typer.Argument(..., help="Text to evaluate"), rules_path: Path | None = typer.Option(None, help="Path to rules YAML")) -> None:
    loader = RuleLoader(base_path=rules_path.parent if rules_path else None)
    bundle = loader.load_files([rules_path]) if rules_path else loader.load_default_bundle()
    engine = PillarsEngine(bundle)
    decision = engine.evaluate(text)
    typer.echo(json.dumps(decision.__dict__, indent=2))
    append_record(decision.__dict__)


def get_app() -> typer.Typer:
    return app


if __name__ == "__main__":
    app()