mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Make the cli example print JSON (#197)
...via the new json_example feature - to make it easier to try out the parser without coding.
This commit is contained in:
parent
f4fbd9b6b3
commit
a0f076acda
3 changed files with 35 additions and 3 deletions
|
@ -23,8 +23,16 @@ fn main() {
|
|||
simple_logger::init().unwrap();
|
||||
|
||||
let filename = std::env::args().nth(1).expect(
|
||||
"No arguments provided!\n\n\
|
||||
Usage: cargo run --example cli FILENAME.sql [--dialectname]",
|
||||
r#"
|
||||
No arguments provided!
|
||||
|
||||
Usage:
|
||||
$ cargo run --example cli FILENAME.sql [--dialectname]
|
||||
|
||||
To print the parse results as JSON:
|
||||
$ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
|
||||
|
||||
"#,
|
||||
);
|
||||
|
||||
let dialect: Box<dyn Dialect> = match std::env::args().nth(2).unwrap_or_default().as_ref() {
|
||||
|
@ -56,7 +64,17 @@ fn main() {
|
|||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
);
|
||||
println!("Parse results:\n{:#?}", statements);
|
||||
|
||||
if cfg!(feature = "json_example") {
|
||||
#[cfg(feature = "json_example")]
|
||||
{
|
||||
let serialized = serde_json::to_string_pretty(&statements).unwrap();
|
||||
println!("Serialized as JSON:\n{}", serialized);
|
||||
}
|
||||
} else {
|
||||
println!("Parse results:\n{:#?}", statements);
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue