aboutsummaryrefslogtreecommitdiff
path: root/examples/example-help/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example-help/src/main.rs')
-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!();