Skip to content

Commit

Permalink
Merge pull request #5 from developmentseed/cql2textout
Browse files Browse the repository at this point in the history
Add round trip back to CQL2 Text, Start output work for SQL, Add Commands
  • Loading branch information
bitner authored Jul 25, 2024
2 parents 2219ec3 + 8bb1b01 commit 5f0c726
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 87 deletions.
55 changes: 55 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ pest_derive = "2.7.11"
rstest = "0.21.0"
serde = "1.0.204"
serde_derive = "1.0.204"
serde_json = "1.0.120"
serde_json = { version = "1.0.120", features = ["preserve_order"] }
assert-json-diff = "2.0.2"
atty = "0.2.14"
29 changes: 29 additions & 0 deletions src/bin/cql2json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use atty::Stream;
use cql2::parse;
use std::env;
use std::io;
use std::process::ExitCode;

fn main() -> ExitCode {
let args: Vec<String> = env::args().collect();
let mut buffer = String::new();
if args.len() >= 2 {
buffer = args[1].to_string();
} else if atty::isnt(Stream::Stdin) {
io::stdin().read_line(&mut buffer).unwrap();
} else {
println!("Enter CQL2 as Text or JSON, then hit return");
io::stdin().read_line(&mut buffer).unwrap();
}
let parsed = parse(&buffer);
if args.len() == 3 && args[2] == "pretty" {
println!("{}", parsed.as_json_pretty());
} else {
println!("{}", parsed.as_json());
}

if parsed.validate() {
return 0.into();
}
1.into()
}
24 changes: 24 additions & 0 deletions src/bin/cql2text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use atty::Stream;
use cql2::parse;
use std::env;
use std::io;
use std::process::ExitCode;

fn main() -> ExitCode {
let args: Vec<String> = env::args().collect();
let mut buffer = String::new();
if args.len() == 2 {
buffer = args[1].to_string();
} else if atty::isnt(Stream::Stdin) {
io::stdin().read_line(&mut buffer).unwrap();
} else {
println!("Enter CQL2 as Text or JSON, then hit return");
io::stdin().read_line(&mut buffer).unwrap();
}
let parsed = parse(&buffer);
println!("{}", parsed.as_cql2_text());
if parsed.validate() {
return 0.into();
}
1.into()
}
Loading

0 comments on commit 5f0c726

Please sign in to comment.