diff options
Diffstat (limited to 'mingling/src')
| -rw-r--r-- | mingling/src/example_docs.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs index 0a6c1b9..09e84a8 100644 --- a/mingling/src/example_docs.rs +++ b/mingling/src/example_docs.rs @@ -343,6 +343,63 @@ pub mod example_completion {} /// gen_program!(); /// ``` pub mod example_dispatch_tree {} +/// `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 +/// ``` +/// +/// Cargo.toml +/// ```ignore +/// [package] +/// name = "example-exit-code" +/// version = "0.1.0" +/// edition = "2024" +/// +/// [dependencies] +/// mingling = { path = "../../mingling" } +/// ``` +/// +/// main.rs +/// ```ignore +/// use mingling::{ +/// macros::{chain, dispatcher, gen_program, pack, r_println, renderer}, +/// res::ExitCode, +/// setup::ExitCodeSetup, +/// this, +/// }; +/// +/// fn main() { +/// let mut program = ThisProgram::new(); +/// program.with_dispatcher(ErrorCommand); +/// program.with_setup(ExitCodeSetup::<ThisProgram>::default()); +/// program.exec(); +/// } +/// +/// dispatcher!("error", ErrorCommand => ErrorEntry); +/// pack!(ResultError = ()); +/// +/// #[chain] +/// fn handle_error_entry(_prev: ErrorEntry) -> NextProcess { +/// this::<ThisProgram>().modify_res(|r: &mut ExitCode| r.exit_code = 1); +/// return ResultError::default(); +/// } +/// +/// #[renderer] +/// fn render_error(_prev: ResultError) { +/// r_println!("Error!"); +/// } +/// +/// gen_program!(); +/// ``` +pub mod example_exit_code {} /// `Mingling` Example - General Renderer /// /// ## Step1 - Enable Feature |
