aboutsummaryrefslogtreecommitdiff
path: root/examples/example-dispatch-tree/src/main.rs
blob: 104f002698e7dfab2abedbd0ed2af4fd6aeee105 (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
42
43
44
45
46
47
48
//! `Mingling` Example - Dispatch Tree
//!
//! # How to Deploy
//! 1. Enable the `dispatch_tree` feature (`comp` is optional)
//! ```toml
//! mingling = { version = "...", features = [
//!     "dispatch_tree",  // Enable this feature
//!     "comp" // optional
//! ] }
//! ```
//!
//! 2. Using `cargo expand`:
//!
//! ```bash
//! cargo expand --manifest-path examples/example-dispatch-tree/Cargo.toml > expanded.rs
//! cat expanded.rs | grep dispatch_args_trie -A 264
//! ```

#![allow(unused_mut)]

use mingling::macros::{dispatcher, gen_program};

fn main() {
    let mut program = ThisProgram::new();

    // After enabling `dispatch_tree`, this method will no longer exist
    // program.with_dispatcher(CommandGreet);
    //
    // The `CompletionDispatcher` automatically generated by `comp` will also be imported
    // automatically
    // program.with_dispatcher(CompletionDispatcher);

    program.exec();
}

dispatcher!("greet", CommandGreet => EntryGreet);
dispatcher!("help", CommandHelp => EntryHelp);
dispatcher!("quit", CommandQuit => EntryQuit);
dispatcher!("list", CommandList => EntryList);
dispatcher!("status", CommandStatus => EntryStatus);
dispatcher!("save", CommandSave => EntrySave);
dispatcher!("load", CommandLoad => EntryLoad);
dispatcher!("config", CommandConfig => EntryConfig);
dispatcher!("run", CommandRun => EntryRun);
dispatcher!("debug", CommandDebug => EntryDebug);
dispatcher!("version", CommandVersion => EntryVersion);

gen_program!();