From 38b60098e42b4a899eb574f65fa14d4fdbe82f9b Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Fri, 3 Apr 2026 06:34:47 +0200 Subject: Init --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 39b3c4c..c372d84 100644 --- a/README.md +++ b/README.md @@ -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] [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, +} + +impl Filterable for Issue { + fn field(&self, name: &str) -> Option> { + 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)); +} +``` -- cgit v1.3.1