Added error handling to upload subcommand

This commit is contained in:
JandereDev 2021-09-28 15:55:08 +02:00 committed by Ben Schattinger
parent a08eb0b791
commit fd6d7d87b6

View file

@ -100,17 +100,25 @@ pub fn run() -> bool {
.to_string_lossy()
.to_string();
let bar = ProgressBar::new(buf.len() as u64);
bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg}[{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})"));
bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})"));
bar.set_message(&format!("Upload {}", name));
bar.enable_steady_tick(100);
if dest.ends_with('/') {
dest.remove(dest.len() - 1);
}
handle
let res = handle
.write_file(&format!("{}/{}", dest, name), &buf, &mut |remaining| {
bar.set_position((buf.len() - remaining) as u64)
})
.unwrap();
});
match res {
Ok(_) => {
println!("Upload {}: Ok", dest);
}
Err(error) => {
bar.abandon_with_message(&format!("Failed: {}", error));
}
}
bar.finish();
}
} else {