diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-04-03 06:34:47 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-04-03 06:34:47 +0200 |
| commit | 38b60098e42b4a899eb574f65fa14d4fdbe82f9b (patch) | |
| tree | 3956fe1ab8107c5feb043fd466a969da8f5b1f9a /README.md | |
| parent | d20acec5efcad4b3cd493f914d10e3d11cdfee4d (diff) | |
| download | ele-38b60098e42b4a899eb574f65fa14d4fdbe82f9b.tar.gz ele-38b60098e42b4a899eb574f65fa14d4fdbe82f9b.zip | |
Init
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 77 |
1 files changed, 77 insertions, 0 deletions
@@ -1 +1,78 @@ # aip-filter + +Parses and evaluates [AIP-160](https://google.aip.dev/160) filter expressions. + +## Install + +Clone the repository and install it with Cargo: + +```bash +cargo install --path . +``` + +## CLI usage + +```bash +usage: aip-filter [-p|--print] <expr> [file...] +``` + +* `--print` prints the parsed expression instead of evaluating it. +* If no files are given, reads from stdin. + +### Examples + +```bash +# Match if price is between 10 and 100, and status is active +echo '{"price": 93, "status": "active"}' | \ + aip-filter "price > 10 AND price < 100 AND status = active" + +# Match if 'foobar' appears in any field (bare-literal match) +echo '{"id": 1, "msg": "hello foobar"}' | aip-filter "foobar" + +# Match if 'tags' contains 'beta' +echo '{"tags": ["stable", "beta"]}' | aip-filter "tags:beta" + +# Nested field access +echo '{"user": {"settings": {"theme": "dark"}}}' | \ + aip-filter "user.settings.theme = dark" +``` + +## API + +Implement `Filterable` for your type, then call `Expr::evaluate`: + +```rust +use aip_filter::{parse, Value, Filterable}; + +struct Issue { + state: String, + priority: i64, + labels: Vec<String>, +} + +impl Filterable for Issue { + fn field(&self, name: &str) -> Option<Value<'_>> { + match name { + "state" => Some(Value::String(&self.state)), + "priority" => Some(Value::Int(self.priority)), + "labels" => Some(Value::List( + self.labels.iter().map(|l| Value::String(l)).collect() + )), + _ => None, + } + } +} + +fn main() { + let expr = parse("state = \"open\"").unwrap().unwrap(); + let issue = Issue { state: "open".into(), priority: 1, labels: vec![] }; + + if expr.evaluate(&issue) { + println!("got match"); + } else { + println!("no match"); + } + + assert!(expr.evaluate(&issue)); +} +``` |
