Skip to content

Commit

Permalink
fix: pass exit codes with usage bash and usage exec
Browse files Browse the repository at this point in the history
Fixes #149
  • Loading branch information
jdx committed Nov 4, 2024
1 parent d295232 commit bdea224
Show file tree
Hide file tree
Showing 6 changed files with 4,059 additions and 617 deletions.
6 changes: 5 additions & 1 deletion cli/src/cli/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ impl Bash {
cmd.env(key, val);
}

cmd.spawn().into_diagnostic()?.wait().into_diagnostic()?;
let result = cmd.spawn().into_diagnostic()?.wait().into_diagnostic()?;

if !result.success() {
std::process::exit(result.code().unwrap_or(1));
}

Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions cli/src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use miette::IntoDiagnostic;
use usage::Spec;

#[derive(Debug, Args)]
#[clap(visible_alias = "x")]
#[clap(visible_alias = "x", hide = true)]
pub struct Exec {
/// command to execute after parsing usage spec
command: String,
Expand Down Expand Up @@ -53,7 +53,11 @@ impl Exec {
cmd.env(key, val);
}

cmd.spawn().into_diagnostic()?.wait().into_diagnostic()?;
let result = cmd.spawn().into_diagnostic()?.wait().into_diagnostic()?;

if !result.success() {
std::process::exit(result.code().unwrap_or(1));
}

Ok(())
}
Expand Down
10 changes: 9 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,13 @@ pub fn run(args: &[String]) -> Result<()> {
}
}
}
Cli::run(args)
let result = Cli::run(args);
if let Err(err) = &result {
if let Some(_err) = err.downcast_ref::<usage::error::UsageErr>() {
eprintln!("{err:?}");
std::process::exit(181);
}
};

result
}
Loading

0 comments on commit bdea224

Please sign in to comment.