aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/example_docs.rs
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 /mingling/src/example_docs.rs
parentdccc86be272091f4f14be52951f8c02996318cd0 (diff)
Update docs and examples for clap binding with optional error parameter
Diffstat (limited to 'mingling/src/example_docs.rs')
-rw-r--r--mingling/src/example_docs.rs29
1 files changed, 19 insertions, 10 deletions
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
/// )]