aboutsummaryrefslogtreecommitdiff
path: root/examples/example-metadata/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example-metadata/src/main.rs')
-rw-r--r--examples/example-metadata/src/main.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/examples/example-metadata/src/main.rs b/examples/example-metadata/src/main.rs
index 855241e..99a8aae 100644
--- a/examples/example-metadata/src/main.rs
+++ b/examples/example-metadata/src/main.rs
@@ -25,20 +25,16 @@ 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() {
- let mut program = ThisProgram::new();
- program.with_dispatcher(CMDGreet);
- program.with_dispatcher(CMDDescription);
- program.with_dispatcher(CMDNoDescription);
- program.exec_and_exit();
+ ThisProgram::new().exec_and_exit();
}
/// The metadata type attached to an entry.
@@ -60,14 +56,17 @@ pub fn greet_desc() -> Description {
}
// --------- IMPORTANT ---------
-pack!(ResultName = String);
-pack!(DescResult = String);
+#[derive(Grouped, Wrap)]
+pub struct ResultName(String);
+
+#[derive(Grouped, Wrap)]
+pub struct DescResult(String);
/// Chain for `greet` — reads the name and produces a `ResultName`.
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
let name: ResultName = args
- .inner
+ .0
.first()
.cloned()
.unwrap_or_else(|| "World".to_string())
@@ -85,7 +84,7 @@ fn handle_desc(_args: EntryDescription) -> Next {
None => "EntryGreet has no description".to_string(),
};
// --------- IMPORTANT ---------
- DescResult::new(msg).to_render()
+ DescResult(msg).to_render()
}
/// Chain for `nodoc` — asks for metadata on an entry that has none.
@@ -98,7 +97,7 @@ fn handle_nodoc(_args: EntryNoDescription) -> Next {
None => "EntryDescription has no description".to_string(),
};
// --------- IMPORTANT ---------
- DescResult::new(msg).to_render()
+ DescResult(msg).to_render()
}
/// Renders the greeting message with the provided name.