From bb9ecf31850c9495d1e51a1f5d0af7d5e9284f0e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 00:41:22 +0800 Subject: feat: add fallback renderer for unknown commands --- mingling_cli/src/lib.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'mingling_cli') diff --git a/mingling_cli/src/lib.rs b/mingling_cli/src/lib.rs index ae3b0e0..902ab32 100644 --- a/mingling_cli/src/lib.rs +++ b/mingling_cli/src/lib.rs @@ -1,7 +1,7 @@ use mingling::{ - ShellContext, Suggest, + RenderResult, ShellContext, Suggest, consts::HELP_FLAG, - macros::{completion, gen_program, help, suggest}, + macros::{completion, gen_program, help, renderer, suggest}, }; use crate::{ @@ -26,7 +26,7 @@ pub mod utils; #[help] pub fn help_global(_: EntryFallback) -> String { - include_str!("../help/help.txt").parse_color_code() + format!("{}\n", include_str!("../help/help.txt").parse_color_code()) } #[completion(EntryFallback)] @@ -42,4 +42,25 @@ pub fn complete_global(_ctx: &ShellContext) -> Suggest { } } +#[renderer] +pub fn handle_fallback(args: EntryFallback) -> RenderResult { + let mut r = RenderResult::new(); + let args = args.inner; + if !args.is_empty() { + eprintln_cargo!( + r, + "{}", + format!("Unknown command `{}`", args.join(" ")).parse_color_code() + ) + } else { + hprintln_cargo!( + r, + "{}", + "Welcome to MinglingCLI, please use `mling -h` to see available commands" + .parse_color_code(), + ); + } + r +} + gen_program!(); -- cgit