heddle_cli_args/cli/cli_args/
command_suggestions.rs1pub fn suggested_command(unknown: &str) -> Option<&'static str> {
10 match unknown.trim().to_ascii_lowercase().as_str() {
11 "save" | "add" => Some("capture"),
12 "stash" => Some("start"),
13 _ => None,
14 }
15}
16
17pub fn format_unrecognized_suggestion(unknown: &str, suggested: &str) -> String {
19 format!(
20 "error: unrecognized subcommand '{unknown}'\n\n tip: a similar subcommand exists: '{suggested}'\n\nUsage: heddle [OPTIONS] <COMMAND>\n\nFor more information, try '--help'.\n"
21 )
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn save_and_add_suggest_capture() {
30 assert_eq!(suggested_command("save"), Some("capture"));
31 assert_eq!(suggested_command("SAVE"), Some("capture"));
32 assert_eq!(suggested_command("add"), Some("capture"));
33 }
34
35 #[test]
36 fn stash_suggests_start() {
37 assert_eq!(suggested_command("stash"), Some("start"));
38 }
39
40 #[test]
41 fn unknown_verbs_have_no_table_hit() {
42 assert_eq!(suggested_command("statuz"), None);
43 assert_eq!(suggested_command("capture"), None);
44 }
45
46 #[test]
47 fn suggestion_text_names_both_verbs() {
48 let text = format_unrecognized_suggestion("save", "capture");
49 assert!(text.contains("unrecognized subcommand 'save'"));
50 assert!(text.contains("capture"));
51 }
52}