mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 20:50:03 +00:00
Add per-error exit codes
This commit is contained in:
parent
f9e69503b0
commit
f56ed6fc4c
2 changed files with 113 additions and 44 deletions
24
src/main.rs
24
src/main.rs
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue