aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-29 14:24:25 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-29 14:24:25 +0800
commit23930c24b7eaf519d8ed36e4f433790eeb4d07fb (patch)
tree06540a1018c5b7070dc96c50141d49842c74778e
parentdccc86be272091f4f14be52951f8c02996318cd0 (diff)
Update docs and examples for clap binding with optional error parameter
-rw-r--r--examples/example-clap-binding/src/main.rs6
-rw-r--r--mingling/src/example_docs.rs29
-rw-r--r--mingling_macros/src/dispatcher_clap.rs5
3 files changed, 27 insertions, 13 deletions
diff --git a/examples/example-clap-binding/src/main.rs b/examples/example-clap-binding/src/main.rs
index aed437d..d3ad573 100644
--- a/examples/example-clap-binding/src/main.rs
+++ b/examples/example-clap-binding/src/main.rs
@@ -71,9 +71,9 @@ fn main() {
// vvvvvvv vvvvvvvvvvvv vvvvvvvv
#[derive(Default, clap::Parser, Groupped)]
#[dispatcher_clap(
- "greet", CMDGreet, // Bind EntryGreet to "greet" command
- help = true, // Generate clap help for EntryGreet
- error = ErrorGreetParsed // Generate and bind error type for parse failure
+ "greet", CMDGreet, // 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,
// which is then rendered by the renderer
)]
diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs
index b5a78ea..a7e8d2e 100644
--- a/mingling/src/example_docs.rs
+++ b/mingling/src/example_docs.rs
@@ -294,8 +294,8 @@ pub mod example_basic {}
/// > This example demonstrates how to bind clap_derive to Mingling
///
/// **Note**:
-/// If the `error` parameter of the `dispatcher_clap!` macro is enabled, parameters will be parsed using `try_parse_from`
-/// This will cause clap's ColorChoice output to be plain text without ANSI colors
+/// If the `error` parameter of the `dispatcher_clap!` macro is enabled, arguments will be parsed using `try_parse_from`.
+/// If you need such output to support ANSI colors, enable the `color` feature of `clap`.
///
/// Run:
/// ```bash
@@ -344,27 +344,36 @@ pub mod example_basic {}
/// # Import `clap` to your project
/// [dependencies.clap]
/// version = "4.6.1"
-/// # Enable `derive` features
-/// features = ["derive"]
+/// features = [
+/// # Enable `derive` feature to support `clap::Parser`
+/// "derive",
+/// # Enable `color` feature to support ANSI colors
+/// "color",
+/// ]
/// ```
///
/// Source code (./src/main.rs)
/// ```ignore
-/// use mingling::{macros::dispatcher_clap, prelude::*, Groupped};
+/// use mingling::{macros::dispatcher_clap, prelude::*, setup::BasicProgramSetup, Groupped};
///
/// fn main() {
/// let mut program = ThisProgram::new();
///
+/// // --------- IMPORTANT ---------
+/// // Introduce BasicProgramSetup to support ["--help", "-h"] options
+/// program.with_setup(BasicProgramSetup);
+///
/// // Set clap help output mode
/// program.stdout_setting.clap_help_print_behaviour =
-/// mingling::ClapHelpPrintBehaviour::PrintDirectly;
-/// // mingling::ClapHelpPrintBehaviour::WriteToRenderResult
+/// mingling::ClapHelpPrintBehaviour::WriteToRenderResult;
+/// // mingling::ClapHelpPrintBehaviour::PrintDirectly
/// //
/// // PrintDirectly:
/// // Let Clap print help information directly to stdout
/// //
/// // WriteToRenderResult:
/// // Capture Clap's help information and write to RenderResult
+/// // --------- IMPORTANT ---------
///
/// program.with_dispatcher(CMDGreet);
/// program.exec_and_exit();
@@ -378,9 +387,9 @@ pub mod example_basic {}
/// // vvvvvvv vvvvvvvvvvvv vvvvvvvv
/// #[derive(Default, clap::Parser, Groupped)]
/// #[dispatcher_clap(
-/// "greet", CMDGreet, // Bind EntryGreet to "greet" command
-/// help = true, // Generate clap help for EntryGreet
-/// error = ErrorGreetParsed // Generate and bind error type for parse failure
+/// "greet", CMDGreet, // 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,
/// // which is then rendered by the renderer
/// )]
diff --git a/mingling_macros/src/dispatcher_clap.rs b/mingling_macros/src/dispatcher_clap.rs
index 8ef2125..5a6cf4c 100644
--- a/mingling_macros/src/dispatcher_clap.rs
+++ b/mingling_macros/src/dispatcher_clap.rs
@@ -23,6 +23,11 @@ impl Parse for ClapOptions {
// Parse leading comma
input.parse::<Token![,]>()?;
+ // Allow trailing comma
+ if input.is_empty() {
+ break;
+ }
+
let key: Ident = input.parse()?;
input.parse::<Token![=]>()?;