diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-09 17:37:37 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-09 17:37:37 +0800 |
| commit | 2eba732e17cf71dcf8a54b428a1c5e344582c2c2 (patch) | |
| tree | e04266109421a0255625490dc997dc0d55bbf64a /mingling_core/src/program.rs | |
| parent | 10bc4ca7a4b3f14cfb57bf72a6da8aaa1490acf3 (diff) | |
Add exit code control and hook lifecycle features
Diffstat (limited to 'mingling_core/src/program.rs')
| -rw-r--r-- | mingling_core/src/program.rs | 23 |
1 files changed, 19 insertions, 4 deletions
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 |
