From 2eba732e17cf71dcf8a54b428a1c5e344582c2c2 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 9 May 2026 17:37:37 +0800 Subject: Add exit code control and hook lifecycle features --- mingling_core/src/program.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'mingling_core/src/program.rs') diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs index 0d23770..b8a409e 100644 --- a/mingling_core/src/program.rs +++ b/mingling_core/src/program.rs @@ -207,7 +207,7 @@ where } /// Run the command line program - pub async fn exec(self) + pub async fn exec(self) -> i32 where C: 'static + Send + Sync, { @@ -217,29 +217,44 @@ where Err(e) => match e { ProgramExecuteError::DispatcherNotFound => { eprintln!("Dispatcher not found"); - return; + return 1; } ProgramExecuteError::RendererNotFound(renderer_name) => { eprintln!("Renderer `{}` not found", renderer_name); - return; + return 1; } ProgramExecuteError::Other(e) => { eprintln!("{}", e); - return; + return 1; } }, }; // 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()) && stdout_setting.error_output { eprintln!("{}", e); + 1 + } else { + exit_code } + } else { + 0 } } + + /// Run the command line program, then exit + pub async fn exec_and_exit(self) + where + C: 'static + Send + Sync, + { + std::process::exit(self.exec().await) + } } // Sync program -- cgit