blob: 9567c49c25c886f56a3295738bb371313e7ae243 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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!();
|