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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
//! Example Dispatch Tree
//!
//! > This example will introduce how to use `dispatch_tree`
//! > to optimize your command line lookup efficiency
//!
//! When the number of commands in your project increases, you can enable
//! `dispatch_tree` to switch command matching from a linear scan to a
//! character-level trie.
//!
//! Run:
//! ```bash
//! cargo run --manifest-path examples/example-dispatch-tree/Cargo.toml --quiet -- cmd5
//! ```
//!
//! Output:
//! ```plaintext
//! It's works!
//! ```
//!
use mingling::prelude::*;
use std::io::Write;
// --------- IMPORTANT ---------
// You have a large number of subcommands
dispatcher!("cmd1", Entry1);
dispatcher!("cmd2.sub1", Entry2Sub1);
dispatcher!("cmd2.sub2", Entry2Sub2);
dispatcher!("cmd3.sub1.leaf1", Entry3Sub1Leaf1);
dispatcher!("cmd3.sub1.leaf2", Entry3Sub1Leaf2);
dispatcher!("cmd3.sub2", Entry3Sub2);
dispatcher!("cmd4.sub1.subsub1.deep", Entry4Deep);
dispatcher!("cmd4.sub1.subsub2", Entry4SubSub2);
dispatcher!("cmd5", Entry5);
dispatcher!("cmd5.extra", Entry5Extra);
dispatcher!("nested.a.b.c", EntryA);
dispatcher!("nested.a.b.d", EntryB);
dispatcher!("nested.a.e", EntryC);
dispatcher!("nested.f", EntryD);
// --------- IMPORTANT ---------
fn main() {
let program = ThisProgram::new();
program.exec_and_exit();
}
/// Renders the confirmation message for the `cmd5` command.
#[renderer]
fn render_cmd5(_: Entry5) -> RenderResult {
let mut render_result = RenderResult::new();
writeln!(render_result, "It's works!").ok();
render_result
}
gen_program!();
|