From 31b5abfc96013309530025b751293c7de916dcf3 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 22 Jun 2026 20:47:00 +0800 Subject: Add help command with exit code 2 for exitcode example --- examples/example-exitcode/src/main.rs | 14 +++++++++++++- examples/test-examples.toml | 5 +++++ mingling/src/example_docs.rs | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/examples/example-exitcode/src/main.rs b/examples/example-exitcode/src/main.rs index 0e7a019..b0b7467 100644 --- a/examples/example-exitcode/src/main.rs +++ b/examples/example-exitcode/src/main.rs @@ -14,10 +14,16 @@ //! No name provided (with exit code 1) //! ``` -use mingling::{prelude::*, res::ResExitCode, setup::ExitCodeSetup}; +use mingling::{ + macros::help, + prelude::*, + res::ResExitCode, + setup::{BasicProgramSetup, ExitCodeSetup}, +}; fn main() { let mut program = ThisProgram::new(); + program.with_setup(BasicProgramSetup); // --------- IMPORTANT --------- // Register `ExitCodeSetup` for the program to enable exit codes @@ -50,6 +56,12 @@ fn render_result_name(name: ResultName) { r_println!("Hello, {}", *name); } +#[help] +fn help_hello(_p: EntryHello, ec: &mut ResExitCode) { + r_println!("Usage: hello "); + ec.exit_code = 2; +} + // Define renderer, render error message _______________ Inject exit code resource // / /// Renders the error when no name is provided | diff --git a/examples/test-examples.toml b/examples/test-examples.toml index 490361b..038221d 100644 --- a/examples/test-examples.toml +++ b/examples/test-examples.toml @@ -38,6 +38,11 @@ command = "hello" expect.exit-code = 1 expect.result = "No name provided (with exit code 1)" +[[test.example-exitcode]] +command = "hello --help" +expect.exit-code = 2 +expect.result = "Usage: hello " + [[test.example-error-handling]] command = "hello" expect.exit-code = 0 diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs index 5ea04b1..f77d9f6 100644 --- a/mingling/src/example_docs.rs +++ b/mingling/src/example_docs.rs @@ -1108,10 +1108,16 @@ pub mod example_error_handling {} /// /// Source code (./src/main.rs) /// ```ignore -/// use mingling::{prelude::*, res::ResExitCode, setup::ExitCodeSetup}; +/// use mingling::{ +/// macros::help, +/// prelude::*, +/// res::ResExitCode, +/// setup::{BasicProgramSetup, ExitCodeSetup}, +/// }; /// /// fn main() { /// let mut program = ThisProgram::new(); +/// program.with_setup(BasicProgramSetup); /// /// // --------- IMPORTANT --------- /// // Register `ExitCodeSetup` for the program to enable exit codes @@ -1144,6 +1150,12 @@ pub mod example_error_handling {} /// r_println!("Hello, {}", *name); /// } /// +/// #[help] +/// fn help_hello(_p: EntryHello, ec: &mut ResExitCode) { +/// r_println!("Usage: hello "); +/// ec.exit_code = 2; +/// } +/// /// // Define renderer, render error message _______________ Inject exit code resource /// // / /// /// Renders the error when no name is provided | -- cgit