diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-25 23:41:36 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-25 23:41:36 +0800 |
| commit | 4ac7d7dc9e6abec2f3f84dd5baf8b642727f19c3 (patch) | |
| tree | a36a182869f035e52ec7f6b7e64826d90869f438 /mingling_core/src/program/exec.rs | |
| parent | 7625655d474f6f12e04a11a067f87287badce9f2 (diff) | |
Add help system with `#[help]` macro and `HelpRequest` trait
Diffstat (limited to 'mingling_core/src/program/exec.rs')
| -rw-r--r-- | mingling_core/src/program/exec.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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::<C>(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::<C>(program, current)); + } + loop { let final_exec = stop_next; @@ -179,3 +189,28 @@ fn render<C: ProgramCollect<Enum = C>>(program: &Program<C>, any: AnyOutput<C>) } } } + +#[inline(always)] +#[allow(unused_variables)] +fn render_help<C: ProgramCollect<Enum = C>>( + program: &Program<C>, + entry: AnyOutput<C>, +) -> 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(), + } + } +} |
