The bree command
cargo install --git https://github.com/breeso/bree bree-cliEvery command takes --rules <dir> (or BREE_RULES), the rules directory, which defaults to rules.
bree init
Starts a rules directory:
$ bree init
wrote rules/bree.d.luau
wrote rules/free_shipping.luau
wrote rules/free_shipping.test.luau
Next: bree checkbree.d.luau declares Bree's globals (int, invalid, test, expect) for your editor (Editor setup). The example rule and its tests are only written into a directory with no .luau files yet. Run bree init again after upgrading Bree to refresh bree.d.luau; it never overwrites your own files.
bree check
Type checks every rule, module and test in strict mode, then runs every test:
$ bree check
ok free_shipping 3 tests passed
1 rule, 3 tests passedExits 0 when everything passes and 1 otherwise, so it fits in CI and pre-commit hooks. Problems print as file:line: message:
rules/free_shipping.test.luau:5: test "US orders ship free from $50" failed
expected { free = true }
got { free = false }
FAIL free_shipping 1 of 3 tests failed
1 rule: 2 tests passed, 1 failed--json prints the same report for tools: ok, every rule with its file, digest and fingerprint, every problem, and every test with its result:
{
"ok": false,
"rules": [
{ "name": "free_shipping", "file": "rules/free_shipping.luau", "digest": "sha256:f7c9611f...", "fingerprint": "ef6a9cd84918712d" }
],
"problems": [],
"tests": [
{ "file": "rules/free_shipping.test.luau", "name": "US orders ship free from $50", "passed": false, "failure": { "line": 5, "message": "expected { free = true }\n got { free = false }" } }
]
}bree run <rule>
Evaluates a rule once and prints the decision. The input is read from standard input, or from a file with --input:
$ echo '{"order_total_cents": 8000, "country": "CA"}' | bree run free_shipping
{
"rule": "free_shipping",
"digest": "sha256:f7c9611f58d4f678cfc0ae1b74b66a9f69e51dc05aad015e1f54b18e5917855c",
"output": {
"free": true
}
}| Exit | |
|---|---|
| 0 | a decision |
| 2 | no decision: the error is printed as JSON on standard output |
| 1 | the rules did not load, or the input could not be read |
bree serve
Serves the HTTP API, and picks up changes to the rules as they pass their checks:
$ bree serve --addr 127.0.0.1:7171 --reload-ms 1000
bree 0.1.0 serving 1 rule from rules on http://127.0.0.1:7171