refactor(command_parser): improve the invalid flags error

This commit is contained in:
dusk 2025-03-29 14:51:58 +09:00
parent 3e65d74bc4
commit 87f6fe9d75
No known key found for this signature in database

View file

@ -182,16 +182,9 @@ pub fn parse_command(
}
write!(
&mut error,
" {} not applicable in this command (`{prefix}{input}`). Applicable flags are the following:",
(invalid_flags.len() > 1).then_some("are").unwrap_or("is")
" {} seem to be applicable in this command (`{prefix}{command}`).",
(invalid_flags.len() > 1).then_some("don't").unwrap_or("doesn't")
).expect("oom");
for (idx, flag) in command.flags.iter().enumerate() {
write!(&mut error, " `{flag}`").expect("oom");
if idx < command.flags.len() - 1 {
error.push_str(", ");
}
}
error.push_str(".");
return Err(error);
}
println!("{} {flags:?} {params:?}", command.cb);