Repository: clap-rs/clap
Pull request #4663 (2023-01-23 16:03:24)

fix: Make cmd variable (bash completion) local
Fix for the generation bash completion script, the `cmd` variable should be local, `cmds` was probably a typo.

fredrik-jansson-se: Not sure why the lint commits/lint commits (PR) failed, happy to fix if someone can explain what needs to be fixed :)
epage: > Not sure why the lint commits/lint commits (PR) failed, happy to fix if someone can explain what needs to be fixed :)

The error is:
```
4c8ac00: error Commit is not in Conventional format: Missing type in the commit summary, expected `type: description`
```
which is based on https://www.conventionalcommits.org/en/v1.0.0/

but the log also says:
```
If this fails, don't sweat it. We're trying to encourage clear communication and not hinder contributions.
If it is a reasonable issue and you lack time or feel uncomfortable fixing it yourself,
let us know and we can mentor or fix it.
```

Patch:
diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs
index e110537e..df955761 100644
--- a/clap_complete/src/shells/bash.rs
+++ b/clap_complete/src/shells/bash.rs
@@ -22,7 +22,7 @@ impl Generator for Bash {
             buf,
             format!(
                 "_{name}() {{
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur=\"${{COMP_WORDS[COMP_CWORD]}}\"
     prev=\"${{COMP_WORDS[COMP_CWORD-1]}}\"
diff --git a/src/parser/features/suggestions.rs b/src/parser/features/suggestions.rs
index b64fcce3..f0aa5026 100644
--- a/src/parser/features/suggestions.rs
+++ b/src/parser/features/suggestions.rs
@@ -72,85 +72,34 @@ where
     }
 }
 
-#[cfg(all(test, feature = "suggestions"))]
+#[cfg(all(test, features = "suggestions"))]
 mod test {
     use super::*;
 
     #[test]
-    fn missing_letter() {
+    fn possible_values_match() {
         let p_vals = ["test", "possible", "values"];
-        assert_eq!(did_you_mean("tst", p_vals.iter()), vec!["test"]);
+        assert_eq!(did_you_mean("tst", p_vals.iter()), Some("test"));
     }
 
     #[test]
-    fn ambiguous() {
-        let p_vals = ["test", "temp", "possible", "values"];
-        assert_eq!(did_you_mean("te", p_vals.iter()), vec!["test", "temp"]);
+    fn possible_values_match() {
+        let p_vals = ["test", "temp"];
+        assert_eq!(did_you_mean("te", p_vals.iter()), Some("test"));
     }
 
     #[test]
-    fn unrelated() {
+    fn possible_values_nomatch() {
         let p_vals = ["test", "possible", "values"];
-        assert_eq!(
-            did_you_mean("hahaahahah", p_vals.iter()),
-            Vec::<String>::new()
-        );
-    }
-
-    #[test]
-    fn best_fit() {
-        let p_vals = [
-            "test",
-            "possible",
-            "values",
-            "alignmentStart",
-            "alignmentScore",
-        ];
-        assert_eq!(
-            did_you_mean("alignmentScorr", p_vals.iter()),
-            vec!["alignmentStart", "alignmentScore"]
-        );
+        assert!(did_you_mean("hahaahahah", p_vals.iter()).is_none());
     }
 
     #[test]
-    fn flag_missing_letter() {
+    fn flag() {
         let p_vals = ["test", "possible", "values"];
         assert_eq!(
-            did_you_mean_flag("tst", &[], p_vals.iter(), []),
-            Some(("test".to_owned(), None))
-        );
-    }
-
-    #[test]
-    fn flag_ambiguous() {
-        let p_vals = ["test", "temp", "possible", "values"];
-        assert_eq!(
-            did_you_mean_flag("te", &[], p_vals.iter(), []),
-            Some(("temp".to_owned(), None))
-        );
-    }
-
-    #[test]
-    fn flag_unrelated() {
-        let p_vals = ["test", "possible", "values"];
-        assert_eq!(
-            did_you_mean_flag("hahaahahah", &[], p_vals.iter(), []),
-            None
-        );
-    }
-
-    #[test]
-    fn flag_best_fit() {
-        let p_vals = [
-            "test",
-            "possible",
-            "values",
-            "alignmentStart",
-            "alignmentScore",
-        ];
-        assert_eq!(
-            did_you_mean_flag("alignmentScorr", &[], p_vals.iter(), []),
-            Some(("alignmentScore".to_owned(), None))
+            did_you_mean_flag("tst", p_vals.iter(), []),
+            Some(("test", None))
         );
     }
 }


Test patch:
diff --git a/clap_complete/tests/snapshots/aliases.bash b/clap_complete/tests/snapshots/aliases.bash
index 0ca8e493..5eb51c82 100644
--- a/clap_complete/tests/snapshots/aliases.bash
+++ b/clap_complete/tests/snapshots/aliases.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/basic.bash b/clap_complete/tests/snapshots/basic.bash
index 70946e79..b381b977 100644
--- a/clap_complete/tests/snapshots/basic.bash
+++ b/clap_complete/tests/snapshots/basic.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/feature_sample.bash b/clap_complete/tests/snapshots/feature_sample.bash
index 8ea49145..6289845f 100644
--- a/clap_complete/tests/snapshots/feature_sample.bash
+++ b/clap_complete/tests/snapshots/feature_sample.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/quoting.bash b/clap_complete/tests/snapshots/quoting.bash
index e387c0bc..940dba1b 100644
--- a/clap_complete/tests/snapshots/quoting.bash
+++ b/clap_complete/tests/snapshots/quoting.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/special_commands.bash b/clap_complete/tests/snapshots/special_commands.bash
index 31b5354a..139b4d55 100644
--- a/clap_complete/tests/snapshots/special_commands.bash
+++ b/clap_complete/tests/snapshots/special_commands.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/sub_subcommands.bash b/clap_complete/tests/snapshots/sub_subcommands.bash
index 4c2573a7..80eed4e8 100644
--- a/clap_complete/tests/snapshots/sub_subcommands.bash
+++ b/clap_complete/tests/snapshots/sub_subcommands.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/value_hint.bash b/clap_complete/tests/snapshots/value_hint.bash
index 11fb3962..f92d4021 100644
--- a/clap_complete/tests/snapshots/value_hint.bash
+++ b/clap_complete/tests/snapshots/value_hint.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
diff --git a/clap_complete/tests/snapshots/value_terminator.bash b/clap_complete/tests/snapshots/value_terminator.bash
index 3b4bc730..f9eef4c2 100644
--- a/clap_complete/tests/snapshots/value_terminator.bash
+++ b/clap_complete/tests/snapshots/value_terminator.bash
@@ -1,5 +1,5 @@
 _my-app() {
-    local i cur prev opts cmds
+    local i cur prev opts cmd
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"