diff options
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 |
