diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-23 23:41:04 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-23 23:49:34 +0800 |
| commit | 0a2ef958c0dca21d19e4ffc38ba5a7c4078e182a (patch) | |
| tree | c82fc4242ed393b132ba514eb434d722e7d9c387 /examples/example-exit-code/src | |
| parent | ccab1940c019dfbfb7dfcbbe4cb927258933755f (diff) | |
Rework examples and add entry macro for testing
Diffstat (limited to 'examples/example-exit-code/src')
| -rw-r--r-- | examples/example-exit-code/src/main.rs | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/examples/example-exit-code/src/main.rs b/examples/example-exit-code/src/main.rs deleted file mode 100644 index c9b3c92..0000000 --- a/examples/example-exit-code/src/main.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! `Mingling` Example - Exit Code -//! -//! This example demonstrates how to modify the program's exit code using `ExitCodeSetup`. -//! By default, the program exits with code 0. This example shows: -//! 1. Using `dispatcher!` to define an error command, -//! 2. Using `chain!` to handle errors and set a custom exit code via `ProgramExitCode`, -//! 3. Using `renderer!` to print an error message. -//! -//! # How to Run -//! ```bash -//! cargo run --manifest-path ./examples/example-exit-code/Cargo.toml -- error -//! ``` - -use mingling::prelude::*; -use mingling::{res::ExitCode, setup::ExitCodeSetup}; - -fn main() { - let mut program = ThisProgram::new(); - program.with_dispatcher(ErrorCommand); - program.with_setup(ExitCodeSetup::<ThisProgram>::default()); - program.exec_and_exit(); -} - -dispatcher!("error", ErrorCommand => ErrorEntry); -pack!(ResultError = ()); - -#[chain] -fn handle_error_entry(_prev: ErrorEntry, ec: &mut ExitCode) -> Next { - ec.exit_code = 1; - return ResultError::default(); -} - -#[renderer] -fn render_error(_prev: ResultError, ec: &ExitCode) { - r_println!("Exit with exit code: {}", ec.exit_code); -} - -gen_program!(); |
