-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Returns `Result<()>` instead of bools from validation method - Removes `validate_str` - Adds crate-specific error based on `thiserror` - Adds some doctests
- Loading branch information
Showing
5 changed files
with
143 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
use cql2_rs::parse; | ||
use std::io::{self, BufRead}; | ||
fn main() -> io::Result<()> { | ||
for line in io::stdin().lock().lines() { | ||
let parsed = parse(&line?); | ||
use cql2_rs::Validator; | ||
use std::io::BufRead; | ||
|
||
fn main() { | ||
let debug_level: u8 = std::env::var("CQL2_DEBUG_LEVEL") | ||
.map(|s| { | ||
s.parse() | ||
.unwrap_or_else(|_| panic!("CQL2_DEBUG_LEVEL should be an integer: {}", s)) | ||
}) | ||
.unwrap_or(1); | ||
let validator = Validator::new().unwrap(); | ||
|
||
let mut ok = true; | ||
for line in std::io::stdin().lock().lines() { | ||
let parsed = cql2_rs::parse(&line.unwrap()); | ||
println!("Parsed: {:#?}", &parsed); | ||
println!("{}", parsed.as_json()); | ||
println!("{}", parsed.to_json().unwrap()); | ||
let value = serde_json::to_value(parsed).unwrap(); | ||
|
||
if let Err(err) = validator.validate(&value) { | ||
match debug_level { | ||
0 => println!("-----------\nCQL2 Is Invalid!\n---------------"), | ||
1 => println!("-----------\n{err}\n---------------"), | ||
2 => println!("-----------\n{err:?}\n---------------"), | ||
_ => println!("-----------\n{err:?}\n---------------"), | ||
} | ||
ok = false; | ||
} | ||
} | ||
|
||
parsed.validate(); | ||
if !ok { | ||
std::process::exit(1); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters