2022-11-20 01:34:04 +01:00
|
|
|
mod io;
|
2022-11-19 16:36:24 +01:00
|
|
|
mod sql;
|
|
|
|
use clap::{arg, command, Command};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let matches = command!()
|
|
|
|
.subcommand(
|
|
|
|
Command::new("sql")
|
|
|
|
.about("Runs a sql statement on the file")
|
|
|
|
.arg(arg!([statement] "SQL statement"))
|
|
|
|
.arg(arg!(-d --delimiter <String> "Column delimiter").required(false)),
|
|
|
|
)
|
2022-11-20 01:34:04 +01:00
|
|
|
.subcommand(Command::new("print").about("Pretty prints the table"))
|
|
|
|
.subcommand(Command::new("rpq").about("Read parquet file"))
|
2022-11-19 16:36:24 +01:00
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
if let Some(matches) = matches.subcommand_matches("sql") {
|
2022-11-20 01:34:04 +01:00
|
|
|
//if let Some(delimiter) = matches.get_one::<String>("delimiter") {
|
|
|
|
// println!("DEBUG: Delimiter: {delimiter}")
|
|
|
|
//} else {
|
|
|
|
// println!("DEBUG: No delimiter")
|
|
|
|
//}
|
2022-11-19 16:36:24 +01:00
|
|
|
if let Some(statement) = matches.get_one::<String>("statement") {
|
2022-11-20 01:34:04 +01:00
|
|
|
sql::execute(statement);
|
2022-11-19 16:36:24 +01:00
|
|
|
} else {
|
2022-11-20 01:34:04 +01:00
|
|
|
let mut df = io::load_csv_from_stdin();
|
|
|
|
io::dump_csv_to_stdout(&mut df);
|
2022-11-19 16:36:24 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-20 01:34:04 +01:00
|
|
|
|
|
|
|
if let Some(_matches) = matches.subcommand_matches("print") {
|
|
|
|
let df = io::load_csv_from_stdin();
|
|
|
|
println!("{}", df)
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(_matches) = matches.subcommand_matches("rpq") {
|
|
|
|
let mut df = io::load_parquet_from_stdin();
|
|
|
|
io::dump_csv_to_stdout(&mut df);
|
|
|
|
}
|
2022-11-19 16:36:24 +01:00
|
|
|
}
|