From ddddc42b13c99ffa0fd749fc2cf59dde3d9d7de8 Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Mon, 5 Aug 2024 14:07:43 +0200 Subject: [PATCH] Exit code when an error occurred --- src/main.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 03e842f..46ba72e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,19 +41,21 @@ async fn main() -> Result<(), Box> { )?; let cli = CliArgs::parse(); - if let Err(err) = handle_args(cli, &term).await { - term.write_line( - format!( - "{}: {}\nDetails: {:?}", - bold_style.clone().red().apply_to("Error"), - err, - err.source() - ) - .as_str(), - )?; + match handle_args(cli, &term).await { + Err(err) => { + term.write_line( + format!( + "{}: {}\nDetails: {:?}", + bold_style.clone().red().apply_to("Error"), + &err, + &err.source() + ) + .as_str(), + )?; + std::process::exit(1); + } + Ok(_) => Ok(()), } - - Ok(()) } async fn handle_args(cli: CliArgs, term: &Term) -> AppResult<()> {