aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 03:27:46 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 03:27:46 +0800
commitc23c590330af83afb6e146bcd9b0a274b3689d22 (patch)
tree34599cf2737ce4de22653c9ccae2d60a38a15842 /examples
parent6980fbf2f9fb4c599d8dc6ff549a8b3288eb24e9 (diff)
refactor!: remove Node type and simplify dispatcher macro syntax
The `dispatcher!` macro no longer requires a `CMD*` dispatcher type argument; the dispatcher struct is now generated internally as `__Dispatcher{Pascal}`. The `Node` type, `node!` macro, and `Dispatcher::node()` / `clone_dispatcher()` methods are removed.
Diffstat (limited to 'examples')
-rw-r--r--examples/example-argument-parse/src/main.rs4
-rw-r--r--examples/example-argument-picker/src/main.rs2
-rw-r--r--examples/example-async-support/src/main.rs2
-rw-r--r--examples/example-basic/src/main.rs2
-rw-r--r--examples/example-clap-binding/src/main.rs2
-rw-r--r--examples/example-combine-pathf-metadata/src/sub/mod.rs2
-rw-r--r--examples/example-command-macro/src/main.rs8
-rw-r--r--examples/example-completion/src/main.rs2
-rw-r--r--examples/example-custom-pickable/src/main.rs2
-rw-r--r--examples/example-dispatch-tree/src/main.rs28
-rw-r--r--examples/example-enum-tag/src/main.rs2
-rw-r--r--examples/example-error-handling/src/main.rs2
-rw-r--r--examples/example-exitcode/src/main.rs2
-rw-r--r--examples/example-help/src/main.rs2
-rw-r--r--examples/example-hook/src/main.rs2
-rw-r--r--examples/example-implicit-dispatcher/src/main.rs7
-rw-r--r--examples/example-lazy-resources/src/main.rs4
-rw-r--r--examples/example-metadata/src/main.rs6
-rw-r--r--examples/example-pack-err/src/main.rs4
-rw-r--r--examples/example-panic-unwind/src/main.rs2
-rw-r--r--examples/example-pathfinder/src/sub/mod.rs2
-rw-r--r--examples/example-repl-basic/src/main.rs8
-rw-r--r--examples/example-resources/src/main.rs4
-rw-r--r--examples/example-setup/src/main.rs2
-rw-r--r--examples/example-structural-renderer/src/main.rs2
-rw-r--r--examples/example-unit-test/src/main.rs2
26 files changed, 54 insertions, 53 deletions
diff --git a/examples/example-argument-parse/src/main.rs b/examples/example-argument-parse/src/main.rs
index d7c8681..d45c4af 100644
--- a/examples/example-argument-parse/src/main.rs
+++ b/examples/example-argument-parse/src/main.rs
@@ -21,8 +21,8 @@
use mingling::{macros::route, prelude::*};
use std::io::Write;
-dispatcher!("transfer", CMDTransfer => EntryTransfer);
-dispatcher!("strict-transfer", CMDStrictTransfer => EntryStrictTransfer);
+dispatcher!("transfer", EntryTransfer);
+dispatcher!("strict-transfer", EntryStrictTransfer);
pack!(ResultFile = (bool, usize, String)); // (IsDir, Size, Name)
diff --git a/examples/example-argument-picker/src/main.rs b/examples/example-argument-picker/src/main.rs
index 36b552e..99eee30 100644
--- a/examples/example-argument-picker/src/main.rs
+++ b/examples/example-argument-picker/src/main.rs
@@ -42,7 +42,7 @@ use mingling::setup::picker::BasicProgramSetup;
// --------- IMPORTANT ---------
-dispatcher!("calc", CMDCalculate => EntryCalculate);
+dispatcher!("calc", EntryCalculate);
pack_err!(ErrorNumberANotProvided);
pack_err!(ErrorNumberBNotProvided);
diff --git a/examples/example-async-support/src/main.rs b/examples/example-async-support/src/main.rs
index 1b6c194..ac1bcc1 100644
--- a/examples/example-async-support/src/main.rs
+++ b/examples/example-async-support/src/main.rs
@@ -39,7 +39,7 @@ async fn main() {
// --------- IMPORTANT ---------
}
-dispatcher!("download", CMDDownload => EntryDownload);
+dispatcher!("download", EntryDownload);
pack!(ResultDownloaded = String);
diff --git a/examples/example-basic/src/main.rs b/examples/example-basic/src/main.rs
index 418ed95..44736ad 100644
--- a/examples/example-basic/src/main.rs
+++ b/examples/example-basic/src/main.rs
@@ -22,7 +22,7 @@ use std::io::Write;
// | / _________ entry, records raw arguments
// | | / ^^^^^^^^^^^^^
// vvvvv vvvvvvvv vvvvvvvvvv \_ equivalent to pack!(EntryGreet = Vec<String>)
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
fn main() {
// Create a new ThisProgram
diff --git a/examples/example-clap-binding/src/main.rs b/examples/example-clap-binding/src/main.rs
index 449fee3..6ff963b 100644
--- a/examples/example-clap-binding/src/main.rs
+++ b/examples/example-clap-binding/src/main.rs
@@ -71,7 +71,7 @@ fn main() {
// vvvvvvv vvvvvvvvvvvv vvvvvvv
#[derive(Default, clap::Parser, Grouped)]
#[dispatcher_clap(
- "greet", CMDGreet, // Bind EntryGreet to "greet" command
+ "greet", // Bind EntryGreet to "greet" command
help = true, // Generate clap help for EntryGreet
error = ErrorGreetParsed, // Generate and bind error type for parse failure
// ^^^^^\__ Using `error` intercepts parse failure information into the specified type,
diff --git a/examples/example-combine-pathf-metadata/src/sub/mod.rs b/examples/example-combine-pathf-metadata/src/sub/mod.rs
index 2e6776e..ba56285 100644
--- a/examples/example-combine-pathf-metadata/src/sub/mod.rs
+++ b/examples/example-combine-pathf-metadata/src/sub/mod.rs
@@ -8,7 +8,7 @@ use std::io::Write;
// Implicit dispatcher form — creates `CMDHello` / `EntryHello` in this module
dispatcher!("hello");
// Creates `CMDDescription` / `EntryDescription` in this module
-dispatcher!("desc", CMDDescription => EntryDescription);
+dispatcher!("desc", EntryDescription);
/// The metadata type attached to an entry (`DataType`).
#[derive(Debug, PartialEq, Eq)]
diff --git a/examples/example-command-macro/src/main.rs b/examples/example-command-macro/src/main.rs
index d080043..e525098 100644
--- a/examples/example-command-macro/src/main.rs
+++ b/examples/example-command-macro/src/main.rs
@@ -26,21 +26,21 @@ pack!(ResultGreeting = String);
pack!(ResultGoodbye = ());
// --------- IMPORTANT ---------
-// Auto-generates dispatcher!("hello.world", CMDHelloWorld => EntryHelloWorld);
+// Auto-generates dispatcher!("hello.world", EntryHelloWorld);
#[command]
fn hello_world() -> ResultGreeting {
ResultGreeting::new("World".to_string())
}
-// Auto-generates dispatcher!("hello-world", CMDGreetSomeone => EntryGreetSomeone);
+// Auto-generates dispatcher!("hello-world", EntryGreetSomeone);
#[command(node = "greet-someone")]
fn greet_someone(args: Vec<String>) -> ResultGreeting {
let name = args.pick_or(&arg![String], || "World".to_string()).unwrap();
ResultGreeting::new(name)
}
-// Auto-generates dispatcher!("goodbye", CMDGoodBye => EntryGoodBye);
-#[command(name = CMDGoodBye, entry = EntryGoodBye)]
+// Auto-generates dispatcher!("goodbye", EntryGoodBye);
+#[command(entry = EntryGoodBye)]
fn goodbye() -> ResultGoodbye {
ResultGoodbye::default()
}
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 29d6026..7de41f6 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -96,7 +96,7 @@ fn complete_greet_entry(ctx: &ShellContext) -> Suggest {
}
// --------- IMPORTANT ---------
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
pack!(ResultName = (u8, String));
#[chain]
diff --git a/examples/example-custom-pickable/src/main.rs b/examples/example-custom-pickable/src/main.rs
index ece5d13..8265b09 100644
--- a/examples/example-custom-pickable/src/main.rs
+++ b/examples/example-custom-pickable/src/main.rs
@@ -41,7 +41,7 @@ impl Pickable for Address {
}
// --------- IMPORTANT ---------
-dispatcher!("connect", CMDConnect => EntryConnect);
+dispatcher!("connect", EntryConnect);
pack!(ErrorParseAddressFailed = ());
#[chain]
diff --git a/examples/example-dispatch-tree/src/main.rs b/examples/example-dispatch-tree/src/main.rs
index a25af2a..bba9c2e 100644
--- a/examples/example-dispatch-tree/src/main.rs
+++ b/examples/example-dispatch-tree/src/main.rs
@@ -23,20 +23,20 @@ use std::io::Write;
// --------- IMPORTANT ---------
// You have a large number of subcommands
-dispatcher!("cmd1", CMD1 => Entry1);
-dispatcher!("cmd2.sub1", CMD2Sub1 => Entry2Sub1);
-dispatcher!("cmd2.sub2", CMD2Sub2 => Entry2Sub2);
-dispatcher!("cmd3.sub1.leaf1", CMD3Sub1Leaf1 => Entry3Sub1Leaf1);
-dispatcher!("cmd3.sub1.leaf2", CMD3Sub1Leaf2 => Entry3Sub1Leaf2);
-dispatcher!("cmd3.sub2", CMD3Sub2 => Entry3Sub2);
-dispatcher!("cmd4.sub1.subsub1.deep", CMD4Deep => Entry4Deep);
-dispatcher!("cmd4.sub1.subsub2", CMD4SubSub2 => Entry4SubSub2);
-dispatcher!("cmd5", CMD5 => Entry5);
-dispatcher!("cmd5.extra", CMD5Extra => Entry5Extra);
-dispatcher!("nested.a.b.c", CMDA => EntryA);
-dispatcher!("nested.a.b.d", CMDB => EntryB);
-dispatcher!("nested.a.e", CMDC => EntryC);
-dispatcher!("nested.f", CMDD => EntryD);
+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() {
diff --git a/examples/example-enum-tag/src/main.rs b/examples/example-enum-tag/src/main.rs
index 884bc1d..2966036 100644
--- a/examples/example-enum-tag/src/main.rs
+++ b/examples/example-enum-tag/src/main.rs
@@ -73,7 +73,7 @@ pub enum ProgrammingLanguages {
impl PickableEnum for ProgrammingLanguages {}
// --------- IMPORTANT ---------
-dispatcher!("lang-select", CMDLanguageSelection => EntryLanguageSelection);
+dispatcher!("lang-select", EntryLanguageSelection);
#[chain]
fn handle_language_selection(args: EntryLanguageSelection) -> Next {
diff --git a/examples/example-error-handling/src/main.rs b/examples/example-error-handling/src/main.rs
index e9c0f57..05b451b 100644
--- a/examples/example-error-handling/src/main.rs
+++ b/examples/example-error-handling/src/main.rs
@@ -26,7 +26,7 @@ use std::io::Write;
// In Mingling, instead of using ? to propagate errors upward,
// errors are treated as branches that continue execution.
-dispatcher!("hello", CMDHello => EntryHello);
+dispatcher!("hello", EntryHello);
// Define error types
pack!(ErrorNoNameProvided = ());
diff --git a/examples/example-exitcode/src/main.rs b/examples/example-exitcode/src/main.rs
index ad712cd..d3e035e 100644
--- a/examples/example-exitcode/src/main.rs
+++ b/examples/example-exitcode/src/main.rs
@@ -34,7 +34,7 @@ fn main() {
program.exec_and_exit();
}
-dispatcher!("hello", CMDHello => EntryHello);
+dispatcher!("hello", EntryHello);
pack!(ErrorNoNameProvided = ());
pack!(ResultName = String);
diff --git a/examples/example-help/src/main.rs b/examples/example-help/src/main.rs
index 90619f5..75170c7 100644
--- a/examples/example-help/src/main.rs
+++ b/examples/example-help/src/main.rs
@@ -16,7 +16,7 @@
use mingling::{macros::help, prelude::*, setup::BasicProgramSetup};
use std::io::Write;
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
// Define help _________ When `program.user_context.help` is `true`
// / the command will not enter `#[chain]` / `#[renderer]`
diff --git a/examples/example-hook/src/main.rs b/examples/example-hook/src/main.rs
index 1304f85..1807e5e 100644
--- a/examples/example-hook/src/main.rs
+++ b/examples/example-hook/src/main.rs
@@ -26,7 +26,7 @@ use mingling::{
};
use std::io::Write;
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
fn main() {
let mut program = ThisProgram::new();
diff --git a/examples/example-implicit-dispatcher/src/main.rs b/examples/example-implicit-dispatcher/src/main.rs
index 69adcfe..89a5ec3 100644
--- a/examples/example-implicit-dispatcher/src/main.rs
+++ b/examples/example-implicit-dispatcher/src/main.rs
@@ -4,9 +4,10 @@
use mingling::prelude::*;
-// When using implicit syntax, the entry and dispatcher names will be automatically derived
-dispatcher!("remote.add" /*, CMDRemoteAdd => EntryRemoteAdd */);
-dispatcher!("remote.remove", CMDRemoteRemove => EntryRemoteRemove);
+// When using implicit syntax, the entry name will be automatically derived
+// from the command name (the dispatcher struct is generated internally)
+dispatcher!("remote.add" /* => EntryRemoteAdd */);
+dispatcher!("remote.remove", EntryRemoteRemove);
fn main() {
ThisProgram::new().exec_and_exit();
diff --git a/examples/example-lazy-resources/src/main.rs b/examples/example-lazy-resources/src/main.rs
index 199608e..cc1604a 100644
--- a/examples/example-lazy-resources/src/main.rs
+++ b/examples/example-lazy-resources/src/main.rs
@@ -49,8 +49,8 @@ fn init_res_large_data() -> ResLargeData {
ResLargeData { data }
}
-dispatcher!("show", CMDShow => EntryShow);
-dispatcher!("none", CMDNone => EntryNone);
+dispatcher!("show", EntryShow);
+dispatcher!("none", EntryNone);
pack!(ResultShow = BTreeMap<Key, Value>);
diff --git a/examples/example-metadata/src/main.rs b/examples/example-metadata/src/main.rs
index 5395614..94facb4 100644
--- a/examples/example-metadata/src/main.rs
+++ b/examples/example-metadata/src/main.rs
@@ -25,13 +25,13 @@ use mingling::{macros::metadata, prelude::*};
use std::io::Write;
// Define the `greet` subcommand
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
// Define the `desc` subcommand, which queries metadata bound to EntryGreet
-dispatcher!("desc", CMDDescription => EntryDescription);
+dispatcher!("desc", EntryDescription);
// Define the `nodoc` subcommand, which queries metadata for an entry that has none
-dispatcher!("nodoc", CMDNoDescription => EntryNoDescription);
+dispatcher!("nodoc", EntryNoDescription);
fn main() {
ThisProgram::new().exec_and_exit();
diff --git a/examples/example-pack-err/src/main.rs b/examples/example-pack-err/src/main.rs
index 901072d..e30e4cb 100644
--- a/examples/example-pack-err/src/main.rs
+++ b/examples/example-pack-err/src/main.rs
@@ -31,8 +31,8 @@ use mingling::setup::StructuralRendererSetup;
use std::io::Write;
use std::path::PathBuf;
-dispatcher!("find", CMDFind => EntryFind);
-dispatcher!("find-structural", CMDFindStructural => EntryFindStructural);
+dispatcher!("find", EntryFind);
+dispatcher!("find-structural", EntryFindStructural);
// --------- IMPORTANT ---------
// `pack_err!` is a convenient macro for defining error types.
diff --git a/examples/example-panic-unwind/src/main.rs b/examples/example-panic-unwind/src/main.rs
index 867e684..e1aa15c 100644
--- a/examples/example-panic-unwind/src/main.rs
+++ b/examples/example-panic-unwind/src/main.rs
@@ -19,7 +19,7 @@ use mingling::config::PanicSilence;
use mingling::{hook::ProgramHook, prelude::*};
use std::io::Write;
-dispatcher!("panic", CMDPanic => EntryPanic);
+dispatcher!("panic", EntryPanic);
pack!(NotPanic = ());
fn main() {
diff --git a/examples/example-pathfinder/src/sub/mod.rs b/examples/example-pathfinder/src/sub/mod.rs
index 8cbc1c5..cf0a97a 100644
--- a/examples/example-pathfinder/src/sub/mod.rs
+++ b/examples/example-pathfinder/src/sub/mod.rs
@@ -2,7 +2,7 @@ use crate::Next;
use mingling::prelude::*;
use std::io::Write;
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
pack!(ResultName = String);
#[chain]
diff --git a/examples/example-repl-basic/src/main.rs b/examples/example-repl-basic/src/main.rs
index dc3d2fe..325619e 100644
--- a/examples/example-repl-basic/src/main.rs
+++ b/examples/example-repl-basic/src/main.rs
@@ -73,10 +73,10 @@ fn main() {
pack!(ErrorDirectoryNotExist = PathBuf);
// Create commands: cd ls exit
-dispatcher!("cd", CMDCd => EntryCd);
-dispatcher!("ls", CMDLs => EntryLs);
-dispatcher!("exit", CMDExit => EntryExit);
-dispatcher!("clear", CMDClear => EntryClear);
+dispatcher!("cd", EntryCd);
+dispatcher!("ls", EntryLs);
+dispatcher!("exit", EntryExit);
+dispatcher!("clear", EntryClear);
// Define data needed for the cd command's execution phase
pack!(StateChangeDirectory = String);
diff --git a/examples/example-resources/src/main.rs b/examples/example-resources/src/main.rs
index 262680a..bb07d74 100644
--- a/examples/example-resources/src/main.rs
+++ b/examples/example-resources/src/main.rs
@@ -40,8 +40,8 @@ fn main() {
program.exec_and_exit();
}
-dispatcher!("current", CMDCurrent => EntryCurrent);
-dispatcher!("modify-current", CMDModifyCurrent => EntryModifyCurrent);
+dispatcher!("current", EntryCurrent);
+dispatcher!("modify-current", EntryModifyCurrent);
// Define chain for modifying current directory _________________ Injected muttable resource
// /
diff --git a/examples/example-setup/src/main.rs b/examples/example-setup/src/main.rs
index b497054..523a567 100644
--- a/examples/example-setup/src/main.rs
+++ b/examples/example-setup/src/main.rs
@@ -53,7 +53,7 @@ fn custom_setup(program: &mut Program<ThisProgram>) {
}
// --------- IMPORTANT ---------
-dispatcher!("greet", CMDGreet => EntryGreet);
+dispatcher!("greet", EntryGreet);
pack!(ResultGreeting = String);
diff --git a/examples/example-structural-renderer/src/main.rs b/examples/example-structural-renderer/src/main.rs
index 8583d46..eca87fc 100644
--- a/examples/example-structural-renderer/src/main.rs
+++ b/examples/example-structural-renderer/src/main.rs
@@ -22,7 +22,7 @@ use mingling::{parser::Picker, setup::StructuralRendererSetup, Grouped, Structur
use serde::Serialize;
use std::io::Write;
-dispatcher!("render", CMDRender => EntryRender);
+dispatcher!("render", EntryRender);
fn main() {
let mut program = ThisProgram::new();
diff --git a/examples/example-unit-test/src/main.rs b/examples/example-unit-test/src/main.rs
index 140df90..29ff9da 100644
--- a/examples/example-unit-test/src/main.rs
+++ b/examples/example-unit-test/src/main.rs
@@ -65,7 +65,7 @@ mod tests {
// --------- IMPORTANT ---------
}
-dispatcher!("hello", CMDHello => EntryHello);
+dispatcher!("hello", EntryHello);
pack!(ErrorNoNameProvided = ());
pack!(ErrorNameTooLong = u16);