Skip to content

Commit

Permalink
Exit code when an error occurred
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 5, 2024
1 parent daf8dc3 commit ddddc42
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;

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<()> {
Expand Down

0 comments on commit ddddc42

Please sign in to comment.