Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add param validation for datafusion-cli #284

Merged
merged 3 commits into from
May 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
jimexist marked this conversation as resolved.
Show resolved Hide resolved
}
}

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)),
jimexist marked this conversation as resolved.
Show resolved Hide resolved
}
}

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