diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-08 15:48:54 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-08 15:48:54 +0800 |
| commit | e875a80d52e5e44f107366cd4825936c44c824bb (patch) | |
| tree | 0753be45a46c621771787b0abcaac9620e06ea8f /examples/example-dispatch-tree/src/main.rs | |
| parent | d895af6e53eb4a18554b3174f819eb771e81ca05 (diff) | |
Add dispatch tree example and update doc version references
Diffstat (limited to 'examples/example-dispatch-tree/src/main.rs')
| -rw-r--r-- | examples/example-dispatch-tree/src/main.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/example-dispatch-tree/src/main.rs b/examples/example-dispatch-tree/src/main.rs new file mode 100644 index 0000000..104f002 --- /dev/null +++ b/examples/example-dispatch-tree/src/main.rs @@ -0,0 +1,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!(); |
