aboutsummaryrefslogtreecommitdiff
path: root/examples/example-help/src
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-23 23:41:04 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-23 23:49:34 +0800
commit0a2ef958c0dca21d19e4ffc38ba5a7c4078e182a (patch)
treec82fc4242ed393b132ba514eb434d722e7d9c387 /examples/example-help/src
parentccab1940c019dfbfb7dfcbbe4cb927258933755f (diff)
Rework examples and add entry macro for testing
Diffstat (limited to 'examples/example-help/src')
-rw-r--r--examples/example-help/src/main.rs41
1 files changed, 41 insertions, 0 deletions
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 <NAME>
+//! ```
+
+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 <NAME>");
+}
+
+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!();