From: Willy Tarreau Date: Fri, 12 Mar 2021 18:01:59 +0000 (+0100) Subject: MINOR: cli: apply the fuzzy matching on the whole command instead of words X-Git-Tag: v2.4-dev12~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c57dcfe787a6cd73040e9b9a97f6701ebdbe1e3a;p=thirdparty%2Fhaproxy.git MINOR: cli: apply the fuzzy matching on the whole command instead of words 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". --- diff --git a/src/cli.c b/src/cli.c index 8a6f827f7c..6791ff2ae5 100644 --- 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.