From 0a2ef958c0dca21d19e4ffc38ba5a7c4078e182a Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sat, 23 May 2026 23:41:04 +0800 Subject: Rework examples and add entry macro for testing --- examples/example-help/src/main.rs | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/example-help/src/main.rs (limited to 'examples/example-help/src/main.rs') diff --git a/examples/example-help/src/main.rs b/examples/example-help/src/main.rs new file mode 100644 index 0000000..9567c49 --- /dev/null +++ b/examples/example-help/src/main.rs @@ -0,0 +1,41 @@ +//! Example Help +//! +//! > This example demonstrates how to use the `#[help]` macro to generate help information, +//! > enabling `--help` to work +//! +//! Run +//! ```bash +//! cargo run --manifest-path examples/example-help/Cargo.toml --quiet -- greet --help +//! ``` +//! +//! Output: +//! ```plain +//! Usage: greet +//! ``` + +use mingling::{macros::help, prelude::*, setup::BasicProgramSetup}; + +dispatcher!("greet", CMDGreet => EntryGreet); + +// Define help _________ When `program.user_context.help` is `true` +// / the command will not enter `#[chain]` / `#[renderer]` +#[help] // vvvvvvvvvv but instead enter this `#[help]` function +fn help_greet(_prev: EntryGreet) { + r_println!("Usage: greet "); +} + +fn main() { + let mut program = ThisProgram::new(); + + // --------- IMPORTANT --------- + // Add `BasicProgramSetup` to the program + // to enable `--help`, `--quiet`, and other built-in features + program.with_setup(BasicProgramSetup); + // --------- IMPORTANT --------- + + program.with_dispatcher(CMDGreet); + + program.exec_and_exit(); +} + +gen_program!(); -- cgit