Add per-error exit codes

This commit is contained in:
Félix Saparelli 2022-05-31 22:00:24 +12:00
parent f9e69503b0
commit f56ed6fc4c
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
2 changed files with 113 additions and 44 deletions

View file

@ -1,4 +1,4 @@
use std::{path::PathBuf, str::FromStr, time::Instant};
use std::{path::PathBuf, process::exit, str::FromStr, time::Instant};
use cargo_toml::{Package, Product};
use log::{debug, error, info, warn, LevelFilter};
@ -75,7 +75,7 @@ struct Options {
pkg_url: Option<String>,
}
fn main() -> Result<()> {
fn main() -> ! {
let start = Instant::now();
let rt = Runtime::new().unwrap();
@ -87,15 +87,23 @@ fn main() -> Result<()> {
if let Err(err) = result {
debug!("run time: {done:?}");
if let Some(BinstallError::UserAbort) = err.downcast_ref::<BinstallError>() {
warn!("Installation cancelled");
Ok(())
} else {
Err(err)
match err.downcast::<BinstallError>() {
Ok(liberr @ BinstallError::UserAbort) => {
warn!("Installation cancelled");
exit(liberr.exit_code() as _);
}
Ok(liberr) => {
eprintln!("{liberr:?}");
exit(liberr.exit_code() as _);
}
Err(binerr) => {
eprintln!("{binerr:?}");
exit(16);
}
}
} else {
info!("Installation complete! [{done:?}]");
Ok(())
exit(0);
}
}