From 4ac7d7dc9e6abec2f3f84dd5baf8b642727f19c3 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 25 Apr 2026 23:41:36 +0800 Subject: Add help system with `#[help]` macro and `HelpRequest` trait --- mingling_core/src/program/exec.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'mingling_core/src/program/exec.rs') diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index c1eada5..469f6d2 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -16,6 +16,11 @@ where let mut current = dispatch_args_dynamic(program, program.args.clone())?; let mut stop_next = false; + // If the program has Help enabled, skip actual logic and jump to Help + if program.user_context.help { + return Ok(render_help::(program, current)); + } + loop { let final_exec = stop_next; @@ -56,6 +61,11 @@ where let mut current = dispatch_args_dynamic(program, program.args.clone())?; let mut stop_next = false; + // If the program has Help enabled, skip actual logic and jump to Help + if program.user_context.help { + return Ok(render_help::(program, current)); + } + loop { let final_exec = stop_next; @@ -179,3 +189,28 @@ fn render>(program: &Program, any: AnyOutput) } } } + +#[inline(always)] +#[allow(unused_variables)] +fn render_help>( + program: &Program, + entry: AnyOutput, +) -> RenderResult { + #[cfg(not(feature = "general_renderer"))] + { + let mut render_result = RenderResult::default(); + C::render_help(entry, &mut render_result); + render_result + } + #[cfg(feature = "general_renderer")] + { + match program.general_renderer_name { + super::GeneralRendererSetting::Disable => { + let mut render_result = RenderResult::default(); + C::render_help(entry, &mut render_result); + render_result + } + _ => RenderResult::default(), + } + } +} -- cgit