Improve cli argument validation

This commit is contained in:
Daniel M 2021-03-31 14:07:09 +02:00
parent 052c3a358a
commit 182442ba3b

View File

@ -108,6 +108,10 @@ async fn main() -> ResBE<()> {
}
};
if numparal <= 0 {
eprintln!("Invalid value for numdl: {}", numparal);
exit(1);
}
let boost = match arguments.value_of("boost") {
Some(it) => it,
@ -122,11 +126,23 @@ async fn main() -> ResBE<()> {
}
};
if boost <= 0 {
eprintln!("Invalid value for boost: {}", boost);
exit(1);
}
let is_zippy = arguments.is_present("zippyshare");
if arguments.is_present("listfile") {
let listfile = arguments.value_of("listfile").unwrap();
let s_listfile = arguments.value_of("listfile").unwrap();
let listfile = Path::new(s_listfile);
if !listfile.is_file() {
eprintln!("Listfile '{}' does not exist!", s_listfile);
exit(1);
}
let ifile = std::fs::File::open(listfile)?;
@ -177,7 +193,10 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, numparal: i32, boost
let outdir = Path::new(outdir);
if !outdir.exists() {
std::fs::create_dir_all(outdir)?;
if let Err(_e) = std::fs::create_dir_all(outdir) {
eprintln!("Error creating output directory '{}'", outdir.to_str().unwrap());
exit(1);
}
}
let t_start = SystemTime::now();