Some relevant docstrings
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Guillem Borrell 2023-01-19 12:28:50 +00:00
parent 92fec23932
commit 83a4138f64
3 changed files with 17 additions and 3 deletions

View file

@ -1,5 +1,6 @@
use clap::{arg, ArgAction, Command}; use clap::{arg, ArgAction, Command};
// Generate command line options for the csv command
pub fn gen_csv_command() -> Command { pub fn gen_csv_command() -> Command {
Command::new("csv") Command::new("csv")
.about("Read csv, output arrow stream") .about("Read csv, output arrow stream")
@ -29,6 +30,7 @@ pub fn gen_csv_command() -> Command {
) )
} }
// Generate command line options for the schema command
pub fn gen_schema_command() -> Command { pub fn gen_schema_command() -> Command {
Command::new("schema") Command::new("schema")
.about("Several table schema related utilities") .about("Several table schema related utilities")
@ -52,6 +54,7 @@ pub fn gen_schema_command() -> Command {
) )
} }
// Generate command line options for the sql command
pub fn gen_sql_command() -> Command { pub fn gen_sql_command() -> Command {
Command::new("sql") Command::new("sql")
.about("Runs a sql statement on the file") .about("Runs a sql statement on the file")
@ -65,6 +68,7 @@ pub fn gen_sql_command() -> Command {
.arg(arg!(-d --delimiter <String> "Column delimiter").required(false)) .arg(arg!(-d --delimiter <String> "Column delimiter").required(false))
} }
// Generate command line options for the rpq command
pub fn gen_rpq_command() -> Command { pub fn gen_rpq_command() -> Command {
Command::new("rpq") Command::new("rpq")
.about("Read parquet file") .about("Read parquet file")
@ -93,6 +97,7 @@ pub fn gen_rpq_command() -> Command {
) )
} }
// Generate command line options for the wpq command
pub fn gen_wpq_command() -> Command { pub fn gen_wpq_command() -> Command {
Command::new("wpq") Command::new("wpq")
.about("Write to a paquet file") .about("Write to a paquet file")
@ -105,6 +110,7 @@ pub fn gen_wpq_command() -> Command {
.arg(arg!([path] "Path to the new parquet file")) .arg(arg!([path] "Path to the new parquet file"))
} }
// Generate command line options for the print command
pub fn gen_print_command() -> Command { pub fn gen_print_command() -> Command {
Command::new("print") Command::new("print")
.about("Pretty prints the table") .about("Pretty prints the table")

View file

@ -1,9 +1,10 @@
use crate::io; use crate::io;
use crate::sql;
use crate::schema; use crate::schema;
use crate::sql;
use clap::ArgMatches; use clap::ArgMatches;
use polars_lazy::prelude::LazyFrame; use polars_lazy::prelude::LazyFrame;
// Handle csv command
pub fn handle_csv(matches: &ArgMatches) { pub fn handle_csv(matches: &ArgMatches) {
let delimiter = match matches.get_one::<String>("delimiter") { let delimiter = match matches.get_one::<String>("delimiter") {
Some(delimiter) => delimiter.as_bytes()[0], Some(delimiter) => delimiter.as_bytes()[0],
@ -39,6 +40,7 @@ pub fn handle_csv(matches: &ArgMatches) {
} }
} }
// Handle the SQL command
pub fn handle_sql(matches: &ArgMatches) { pub fn handle_sql(matches: &ArgMatches) {
let delimiter = match matches.get_one::<String>("delimiter") { let delimiter = match matches.get_one::<String>("delimiter") {
Some(delimiter) => delimiter.as_bytes()[0], Some(delimiter) => delimiter.as_bytes()[0],
@ -57,6 +59,7 @@ pub fn handle_sql(matches: &ArgMatches) {
} }
} }
// Handle the print command
pub fn handle_print(matches: &ArgMatches) { pub fn handle_print(matches: &ArgMatches) {
let delimiter = match matches.get_one::<String>("delimiter") { let delimiter = match matches.get_one::<String>("delimiter") {
Some(delimiter) => delimiter.as_bytes()[0], Some(delimiter) => delimiter.as_bytes()[0],
@ -70,6 +73,7 @@ pub fn handle_print(matches: &ArgMatches) {
println!("{}", df.collect().expect("Could not collect")); println!("{}", df.collect().expect("Could not collect"));
} }
// Handle the rpq command
pub fn handle_rpq(matches: &ArgMatches) { pub fn handle_rpq(matches: &ArgMatches) {
let mut ldf = LazyFrame::default(); let mut ldf = LazyFrame::default();
if matches.get_flag("stdin") { if matches.get_flag("stdin") {
@ -99,9 +103,9 @@ pub fn handle_rpq(matches: &ArgMatches) {
} }
} }
} }
} }
// Handle the wpq command
pub fn handle_wpq(matches: &ArgMatches) { pub fn handle_wpq(matches: &ArgMatches) {
let delimiter = match matches.get_one::<String>("delimiter") { let delimiter = match matches.get_one::<String>("delimiter") {
Some(delimiter) => delimiter.as_bytes()[0], Some(delimiter) => delimiter.as_bytes()[0],
@ -119,6 +123,7 @@ pub fn handle_wpq(matches: &ArgMatches) {
} }
} }
// Handle the schema command
pub fn handle_schema(matches: &ArgMatches) { pub fn handle_schema(matches: &ArgMatches) {
let delimiter = match matches.get_one::<String>("delimiter") { let delimiter = match matches.get_one::<String>("delimiter") {
Some(delimiter) => delimiter.as_bytes()[0], Some(delimiter) => delimiter.as_bytes()[0],

View file

@ -6,6 +6,7 @@ mod sql;
use clap::command; use clap::command;
fn main() { fn main() {
// Commands definition
let matches = command!() let matches = command!()
.subcommand(commands::gen_csv_command()) .subcommand(commands::gen_csv_command())
.subcommand(commands::gen_schema_command()) .subcommand(commands::gen_schema_command())
@ -14,6 +15,8 @@ fn main() {
.subcommand(commands::gen_rpq_command()) .subcommand(commands::gen_rpq_command())
.subcommand(commands::gen_wpq_command()) .subcommand(commands::gen_wpq_command())
.get_matches(); .get_matches();
// Send the flow to the corresponding handler
if let Some(sub_matches) = matches.subcommand_matches("csv") { if let Some(sub_matches) = matches.subcommand_matches("csv") {
handlers::handle_csv(sub_matches); handlers::handle_csv(sub_matches);
} else if let Some(sub_matches) = matches.subcommand_matches("sql") { } else if let Some(sub_matches) = matches.subcommand_matches("sql") {