diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-29 14:17:14 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-29 14:21:11 +0800 |
| commit | dccc86be272091f4f14be52951f8c02996318cd0 (patch) | |
| tree | 6c99a113364e24482b9a03fbb7152aac83af83fd /examples | |
| parent | e87fc1c89e4508fca6e7fd0ebafd3f17a0b95095 (diff) | |
Enable color feature for clap and fix help and error rendering
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/example-clap-binding/Cargo.toml | 8 | ||||
| -rw-r--r-- | examples/example-clap-binding/src/main.rs | 15 |
2 files changed, 16 insertions, 7 deletions
diff --git a/examples/example-clap-binding/Cargo.toml b/examples/example-clap-binding/Cargo.toml index d261786..a019442 100644 --- a/examples/example-clap-binding/Cargo.toml +++ b/examples/example-clap-binding/Cargo.toml @@ -11,5 +11,9 @@ features = ["clap"] # 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", +] diff --git a/examples/example-clap-binding/src/main.rs b/examples/example-clap-binding/src/main.rs index fd813a6..aed437d 100644 --- a/examples/example-clap-binding/src/main.rs +++ b/examples/example-clap-binding/src/main.rs @@ -3,8 +3,8 @@ //! > 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 @@ -38,21 +38,26 @@ //! For more information, try '--help'. //! ``` -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(); |
