Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass exit codes with usage bash and usage exec #152

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}