]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: apply the fuzzy matching on the whole command instead of words
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Mar 2021 18:01:59 +0000 (19:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Mar 2021 18:09:19 +0000 (19:09 +0100)
Now instead of comparing words at an exact position, we build a fingerprint
made of all of them, so that we can check for them in any position. For
example, "show conn serv" finds "show servers conn" and that "set servers
maxconn" proposes both "set server" and "set maxconn servers".

src/cli.c

index 8a6f827f7cc25dc98fb9d299d8720ca92615a098..6791ff2ae5e7e0b7b85d92eef73fbb54b6b0ed55 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -168,13 +168,16 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
                                        /* this one matches, let's compute the distance between the two
                                         * on the remaining words
                                         */
+                                       memset(word_sig, 0, sizeof(word_sig));
+                                       memset(list_sig, 0, sizeof(list_sig));
+
                                        while (idx < CLI_PREFIX_KW_NB && kw->str_kw[idx] && args[idx] && *args[idx]) {
-                                               make_word_fingerprint(word_sig, args[idx]);
-                                               make_word_fingerprint(list_sig, kw->str_kw[idx]);
+                                               update_word_fingerprint(word_sig, args[idx]);
+                                               update_word_fingerprint(list_sig, kw->str_kw[idx]);
                                                totlen += strlen(args[idx]) + strlen(kw->str_kw[idx]);
-                                               dist += word_fingerprint_distance(word_sig, list_sig);
                                                idx++;
                                        }
+                                       dist = word_fingerprint_distance(word_sig, list_sig);
 
                                        /* insert this one at its place if relevant, in order to keep only
                                         * the best matches.