From 83a4138f64b59fcd979213814b08898fd5f74a15 Mon Sep 17 00:00:00 2001 From: Guillem Borrell Date: Thu, 19 Jan 2023 12:28:50 +0000 Subject: [PATCH] Some relevant docstrings --- src/commands.rs | 6 ++++++ src/handlers.rs | 11 ++++++++--- src/main.rs | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index c3d9b73..88641b5 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,5 +1,6 @@ use clap::{arg, ArgAction, Command}; +// Generate command line options for the csv command pub fn gen_csv_command() -> Command { Command::new("csv") .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 { Command::new("schema") .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 { Command::new("sql") .about("Runs a sql statement on the file") @@ -65,6 +68,7 @@ pub fn gen_sql_command() -> Command { .arg(arg!(-d --delimiter "Column delimiter").required(false)) } +// Generate command line options for the rpq command pub fn gen_rpq_command() -> Command { Command::new("rpq") .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 { Command::new("wpq") .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")) } +// Generate command line options for the print command pub fn gen_print_command() -> Command { Command::new("print") .about("Pretty prints the table") diff --git a/src/handlers.rs b/src/handlers.rs index b360e88..0095aa1 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,9 +1,10 @@ use crate::io; -use crate::sql; use crate::schema; +use crate::sql; use clap::ArgMatches; use polars_lazy::prelude::LazyFrame; +// Handle csv command pub fn handle_csv(matches: &ArgMatches) { let delimiter = match matches.get_one::("delimiter") { 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) { let delimiter = match matches.get_one::("delimiter") { 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) { let delimiter = match matches.get_one::("delimiter") { Some(delimiter) => delimiter.as_bytes()[0], @@ -70,6 +73,7 @@ pub fn handle_print(matches: &ArgMatches) { println!("{}", df.collect().expect("Could not collect")); } +// Handle the rpq command pub fn handle_rpq(matches: &ArgMatches) { let mut ldf = LazyFrame::default(); 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) { let delimiter = match matches.get_one::("delimiter") { 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) { let delimiter = match matches.get_one::("delimiter") { Some(delimiter) => delimiter.as_bytes()[0], @@ -142,4 +147,4 @@ pub fn handle_schema(matches: &ArgMatches) { }; schema::print_create(ldf, name.as_str(), strlen); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 4239702..e981dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ mod sql; use clap::command; fn main() { + // Commands definition let matches = command!() .subcommand(commands::gen_csv_command()) .subcommand(commands::gen_schema_command()) @@ -14,6 +15,8 @@ fn main() { .subcommand(commands::gen_rpq_command()) .subcommand(commands::gen_wpq_command()) .get_matches(); + + // Send the flow to the corresponding handler if let Some(sub_matches) = matches.subcommand_matches("csv") { handlers::handle_csv(sub_matches); } else if let Some(sub_matches) = matches.subcommand_matches("sql") {