Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of work to match cql2 against json #55

Merged
merged 22 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 109 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ keywords = ["cql2"]

[dependencies]
boon = "0.6.0"
derive_is_enum_variant = "0.1.1"
bitner marked this conversation as resolved.
Show resolved Hide resolved
geo-types = "0.7.13"
geojson = "0.24.1"
geozero = "0.14.0"
json_dotpath = "1.1.0"
lazy_static = "1.5"
pest = "2.7"
pest_derive = { version = "2.7", features = ["grammar-extras"] }
Expand Down
10 changes: 9 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use clap::{ArgAction, Parser, ValueEnum};
use cql2::{Expr, Validator};
use serde_json::json;
use std::io::Read;

/// The CQL2 command-line interface.
Expand Down Expand Up @@ -30,6 +31,10 @@ pub struct Cli {
#[arg(long, default_value_t = true, action = ArgAction::Set)]
validate: bool,

/// Reduce the CQL2
#[arg(long, default_value_t = false, action = ArgAction::Set)]
reduce: bool,

/// Verbosity.
///
/// Provide this argument several times to turn up the chatter.
Expand Down Expand Up @@ -95,7 +100,7 @@ impl Cli {
InputFormat::Text
}
});
let expr: Expr = match input_format {
let mut expr: Expr = match input_format {
InputFormat::Json => cql2::parse_json(&input)?,
InputFormat::Text => match cql2::parse_text(&input) {
Ok(expr) => expr,
Expand All @@ -104,6 +109,9 @@ impl Cli {
}
},
};
if self.reduce {
expr.reduce(&json!({}));
bitner marked this conversation as resolved.
Show resolved Hide resolved
}
if self.validate {
let validator = Validator::new().unwrap();
let value = serde_json::to_value(&expr).unwrap();
Expand Down
Loading
Loading