From c824ce41a1dca2323ffdcf872b4904de50065608 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 27 Jun 2026 16:24:27 +0800 Subject: fix(core): respect exit code when render output is suppressed --- mingling_core/src/program/once_exec.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'mingling_core/src') diff --git a/mingling_core/src/program/once_exec.rs b/mingling_core/src/program/once_exec.rs index 4c44597..9d6f1e4 100644 --- a/mingling_core/src/program/once_exec.rs +++ b/mingling_core/src/program/once_exec.rs @@ -48,10 +48,13 @@ where } /// Run the command line program + #[must_use] pub async fn exec(self) -> i32 where C: 'static + Send + Sync, { + use crate::error::ProgramExecuteError; + let stdout_setting = self.stdout_setting.clone(); let result = match self.exec_without_render().await { Ok(r) => r, @@ -61,35 +64,37 @@ where return 1; } ProgramExecuteError::RendererNotFound(renderer_name) => { - eprintln!("Renderer `{}` not found", renderer_name); + eprintln!("Renderer `{renderer_name}` not found"); return 1; } ProgramExecuteError::Other(e) => { - eprintln!("{}", e); + eprintln!("{e}"); return 1; } ProgramExecuteError::Panic(unwinded_error) => { - eprintln!("{}", unwinded_error); + eprintln!("{unwinded_error}"); return 1; } }, }; + // Read exit code + let exit_code = result.exit_code; + // Render result if stdout_setting.render_output && !result.is_empty() { - let exit_code = result.exit_code; - print!("{}", result); + print!("{result}"); if let Err(e) = std::io::Write::flush(&mut std::io::stdout()) && stdout_setting.error_output { - eprintln!("{}", e); + eprintln!("{e}"); 1 } else { exit_code } } else { - 0 + exit_code } } @@ -211,9 +216,11 @@ where }, }; + // Read exit code + let exit_code = result.exit_code; + // Render result if stdout_setting.render_output && !result.is_empty() { - let exit_code = result.exit_code; print!("{result}"); if let Err(e) = std::io::Write::flush(&mut std::io::stdout()) @@ -225,7 +232,7 @@ where exit_code } } else { - 0 + exit_code } } -- cgit