aboutsummaryrefslogtreecommitdiff
path: root/mingling
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-13 07:28:48 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-13 07:28:48 +0800
commit566b43cc15fc8a0bc7f962e05908486dbf53a7d0 (patch)
tree5ab8e84d61367c8e7fb4303eb76722c1a5a35e16 /mingling
parent95c6b979ca399671eed8bf9c72f53cfe5d46f431 (diff)
Add example doc for exit code usage
Diffstat (limited to 'mingling')
-rw-r--r--mingling/src/example_docs.rs57
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