aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/dispatcher_clap.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-29 14:17:14 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-29 14:21:11 +0800
commitdccc86be272091f4f14be52951f8c02996318cd0 (patch)
tree6c99a113364e24482b9a03fbb7152aac83af83fd /mingling_macros/src/dispatcher_clap.rs
parente87fc1c89e4508fca6e7fd0ebafd3f17a0b95095 (diff)
Enable color feature for clap and fix help and error rendering
Diffstat (limited to 'mingling_macros/src/dispatcher_clap.rs')
-rw-r--r--mingling_macros/src/dispatcher_clap.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/mingling_macros/src/dispatcher_clap.rs b/mingling_macros/src/dispatcher_clap.rs
index 42b5276..8ef2125 100644
--- a/mingling_macros/src/dispatcher_clap.rs
+++ b/mingling_macros/src/dispatcher_clap.rs
@@ -173,7 +173,7 @@ pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream
match <#struct_name as ::clap::Parser>::try_parse_from(clap_args) {
Ok(parsed) => parsed.to_chain(),
Err(e) => {
- return #error_struct::new(e.to_string()).to_render()
+ return #error_struct::new(format!("{}", e.render().ansi())).to_render()
},
}
}
@@ -205,15 +205,16 @@ pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream
#[allow(non_snake_case)]
#[::mingling::macros::help]
fn #help_fn_name(_prev: #struct_name) {
+ use std::io::Write;
use clap::ColorChoice;
let this = ::mingling::this::<#program_path>();
match this.stdout_setting.clap_help_print_behaviour {
::mingling::ClapHelpPrintBehaviour::WriteToRenderResult => {
- <#struct_name as ::clap::CommandFactory>::command()
- .color(ColorChoice::Always)
- .write_help(__renderer_inner_result)
- .unwrap();
+ let mut cmd = <#struct_name as ::clap::CommandFactory>::command()
+ .color(ColorChoice::Always);
+ let styled = cmd.render_help();
+ write!(__renderer_inner_result, "{}", styled.ansi()).unwrap();
}
::mingling::ClapHelpPrintBehaviour::PrintDirectly => {
let mut command = <#struct_name as ::clap::CommandFactory>::command();