Skip to content

Commit

Permalink
add param validation for datafusion-cli (#284)
Browse files Browse the repository at this point in the history
* add param validation for datafusion-cli

* Update datafusion-cli/src/main.rs

Co-authored-by: Andrew Lamb <[email protected]>

* Update datafusion-cli/src/main.rs

Co-authored-by: Andrew Lamb <[email protected]>

Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
jimexist and alamb authored May 8, 2021
1 parent b8805d4 commit a947f11
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions datafusion-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ pub async fn main() {
.help("Path to your data, default to current directory")
.short("p")
.long("data-path")
.validator(is_valid_data_dir)
.takes_value(true),
)
.arg(
Arg::with_name("batch-size")
.help("The batch size of each query, or use DataFusion default")
.short("c")
.long("batch-size")
.validator(is_valid_batch_size)
.takes_value(true),
)
.get_matches();
Expand Down Expand Up @@ -100,6 +102,21 @@ pub async fn main() {
rl.save_history(".history").ok();
}

fn is_valid_data_dir(dir: String) -> std::result::Result<(), String> {
if Path::new(&dir).is_dir() {
Ok(())
} else {
Err(format!("Invalid data directory '{}'", dir))
}
}

fn is_valid_batch_size(size: String) -> std::result::Result<(), String> {
match size.parse::<usize>() {
Ok(size) if size > 0 => Ok(()),
_ => Err(format!("Invalid batch size '{}'", size)),
}
}

fn is_exit_command(line: &str) -> bool {
let line = line.trim_end().to_lowercase();
line == "quit" || line == "exit"
Expand Down

0 comments on commit a947f11

Please sign in to comment.