diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-22 20:47:00 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-22 20:47:00 +0800 |
| commit | 31b5abfc96013309530025b751293c7de916dcf3 (patch) | |
| tree | ea151429c4d754e1d2b709e976ba369c534c226b /examples | |
| parent | 5169b9a462a7a3854b8320c8d9e78985a34c5f15 (diff) | |
Add help command with exit code 2 for exitcode example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/example-exitcode/src/main.rs | 14 | ||||
| -rw-r--r-- | examples/test-examples.toml | 5 |
2 files changed, 18 insertions, 1 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 <NAME>"); + 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 <NAME>" + [[test.example-error-handling]] command = "hello" expect.exit-code = 0 |
