diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 00:41:22 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 00:41:22 +0800 |
| commit | bb9ecf31850c9495d1e51a1f5d0af7d5e9284f0e (patch) | |
| tree | 3902e656a43b6404ed4dfa56e257ebf52c930581 | |
| parent | 1cd4a824b3bffbbdf391837288921d538438a751 (diff) | |
feat: add fallback renderer for unknown commands
| -rw-r--r-- | mingling_cli/src/lib.rs | 27 |
1 files changed, 24 insertions, 3 deletions
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!(); |
