diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-26 01:23:39 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-26 01:23:39 +0800 |
| commit | d2c44d5c1cd8df2d150c849e8bd196e15c4015e3 (patch) | |
| tree | 824a2282c8c10923651e76d2c27956e0390ab6fd /mingling_macros/src | |
| parent | 00923e2a4180c39ccc2d0ab51a7548fb7bfa5719 (diff) | |
Add clap_parser feature to mingling_core with help output behavior
config
Diffstat (limited to 'mingling_macros/src')
| -rw-r--r-- | mingling_macros/src/dispatcher_clap.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/mingling_macros/src/dispatcher_clap.rs b/mingling_macros/src/dispatcher_clap.rs index 765a448..5184bce 100644 --- a/mingling_macros/src/dispatcher_clap.rs +++ b/mingling_macros/src/dispatcher_clap.rs @@ -164,6 +164,7 @@ impl Parse for DispatcherClapInput { } } +#[cfg(feature = "clap_parser")] pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream { let attr_input = parse_macro_input!(attr as DispatcherClapInput); let input_struct = parse_macro_input!(item as ItemStruct); @@ -241,9 +242,21 @@ pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream #[allow(non_snake_case)] #[::mingling::macros::help] fn #help_fn_name(_prev: #struct_name) { - <#struct_name as ::clap::CommandFactory>::command() - .write_help(r) - .unwrap(); + use clap::ColorChoice; + + let this = ::mingling::this::<#program_ident>(); + match this.stdout_setting.clap_help_print_behaviour { + ::mingling::ClapHelpPrintBehaviour::WriteToRenderResult => { + <#struct_name as ::clap::CommandFactory>::command() + .color(ColorChoice::Always) + .write_help(r) + .unwrap(); + } + ::mingling::ClapHelpPrintBehaviour::PrintDirectly => { + let mut command = <#struct_name as ::clap::CommandFactory>::command(); + command.print_help().unwrap(); + } + } } }) } else { |
