From fb71a20999edbb028888915b20a4cc1bd22e28da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sat, 25 Jan 2025 10:21:32 -0700 Subject: [PATCH] Propagate the correct exit code from scripts Fixes #198. --- crates/shell/src/execute.rs | 2 +- crates/shell/src/main.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/shell/src/execute.rs b/crates/shell/src/execute.rs index f52d299..ba2fa72 100644 --- a/crates/shell/src/execute.rs +++ b/crates/shell/src/execute.rs @@ -42,6 +42,6 @@ pub async fn execute(text: &str, state: &mut ShellState) -> miette::Result .context("Failed to set CWD")?; Ok(exit_code) } - ExecuteResult::Exit(_, _) => Ok(0), + ExecuteResult::Exit(exit_code, _) => Ok(exit_code), } } diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 773d6c6..f8942e2 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -170,10 +170,11 @@ async fn main() -> miette::Result<()> { debug_parse(&script_text); return Ok(()); } - execute(&script_text, &mut state).await?; + let exit_code = execute(&script_text, &mut state).await?; if options.interact { interactive(Some(state), options.norc).await?; } + std::process::exit(exit_code); // Exit with the correct code } else { interactive(None, options.norc).await?; }