mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Fix -V
behavior (#488)
Fixed #485 * Make `Duration` in MainExit::Success` optional * Fix arg parsing: Print version on `-V` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
9ebcd1d426
commit
f4f6e36984
2 changed files with 21 additions and 13 deletions
|
@ -11,7 +11,7 @@ use miette::Result;
|
|||
use tokio::runtime::Runtime;
|
||||
|
||||
pub enum MainExit {
|
||||
Success(Duration),
|
||||
Success(Option<Duration>),
|
||||
Error(BinstallError),
|
||||
Report(miette::Report),
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ impl Termination for MainExit {
|
|||
fn report(self) -> ExitCode {
|
||||
match self {
|
||||
Self::Success(spent) => {
|
||||
info!("Done in {spent:?}");
|
||||
if let Some(spent) = spent {
|
||||
info!("Done in {spent:?}");
|
||||
}
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Self::Error(err) => err.report(),
|
||||
|
@ -35,11 +37,12 @@ impl Termination for MainExit {
|
|||
impl MainExit {
|
||||
pub fn new(result: Result<Result<()>, BinstallError>, done: Duration) -> Self {
|
||||
result.map_or_else(MainExit::Error, |res| {
|
||||
res.map(|()| MainExit::Success(done)).unwrap_or_else(|err| {
|
||||
err.downcast::<BinstallError>()
|
||||
.map(MainExit::Error)
|
||||
.unwrap_or_else(MainExit::Report)
|
||||
})
|
||||
res.map(|()| MainExit::Success(Some(done)))
|
||||
.unwrap_or_else(|err| {
|
||||
err.downcast::<BinstallError>()
|
||||
.map(MainExit::Error)
|
||||
.unwrap_or_else(MainExit::Report)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,19 @@ fn main() -> MainExit {
|
|||
Err(err) => return MainExit::Error(err),
|
||||
};
|
||||
|
||||
ui::logging(&args);
|
||||
if args.version {
|
||||
println!("{}", env!("CARGO_PKG_VERSION"));
|
||||
MainExit::Success(None)
|
||||
} else {
|
||||
ui::logging(&args);
|
||||
|
||||
let start = Instant::now();
|
||||
let start = Instant::now();
|
||||
|
||||
let result = run_tokio_main(entry::install_crates(args, jobserver_client));
|
||||
let result = run_tokio_main(entry::install_crates(args, jobserver_client));
|
||||
|
||||
let done = start.elapsed();
|
||||
debug!("run time: {done:?}");
|
||||
let done = start.elapsed();
|
||||
debug!("run time: {done:?}");
|
||||
|
||||
MainExit::new(result, done)
|
||||
MainExit::new(result, done)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue