MINOR: cli: sort the suggestions by order of relevance
Now the suggested keywords are sorted with the most relevant ones first
instead of scanning them all in registration order and only dumping the
proposed ones:
- "tra"
trace <module> [cmd [args...]] : manage live tracing
operator : lower the level of the current CLI session to operator
user : lower the level of the current CLI session to user
show trace [<module>] : show live tracing state
- "pool"
show pools : report information about the memory pools usage
add acl : add acl entry
del map : delete map entry
user : lower the level of the current CLI session to user
del acl : delete acl entry
- "sh ta"
show stat : report counters for each proxy and server [desc|json|no-maint|typed|up]*
show tasks : show running tasks
set table [id] : update or create a table entry's data
show table [id]: report table usage stats or dump this table's contents
trace <module> [cmd [args...]] : manage live tracing
- "sh state"
show stat : report counters for each proxy and server [desc|json|no-maint|typed|up]*
set table [id] : update or create a table entry's data
show table [id]: report table usage stats or dump this table's contents
show servers state [id]: dump volatile server information (for backend <id>)
show sess [id] : report the list of current sessions or dump this session
diff --git a/src/cli.c b/src/cli.c
index 010655a..c287444 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -203,7 +203,26 @@
}
}
+ if (matches[0].kw) {
+ /* we have fuzzy matches, let's propose them */
+ for (idx = 0; idx < CLI_MAX_MATCHES; idx++) {
+ kw = matches[idx].kw;
+ if (!kw)
+ break;
+
+ /* stop the dump if some words look very unlikely candidates */
+ if (matches[idx].dist > 5*matches[0].dist/2)
+ break;
+
+ chunk_appendf(tmp, " %s\n", kw->usage);
+ }
+ }
+
list_for_each_entry(kw_list, &cli_keywords.list, list) {
+ /* no full dump if we've already found nice candidates */
+ if (matches[0].kw)
+ break;
+
for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) {
/* in a worker or normal process, don't display master-only commands
@@ -228,19 +247,8 @@
break;
}
- if (kw->usage && idx == length) {
- /* if we've filled some fuzzy matches, let's compare them. We'll
- * just set the idx to their position if they're found and are no
- * further than twice the distance of the best match, otherwise
- * idx will be CLI_MAX_MATCHES, indicating "not found".
- */
- for (idx = 0; matches[0].kw && idx < CLI_MAX_MATCHES; idx++)
- if (kw == matches[idx].kw && matches[idx].dist <= 5*matches[0].dist/2)
- break;
-
- if (idx < CLI_MAX_MATCHES)
- chunk_appendf(tmp, " %s\n", kw->usage);
- }
+ if (kw->usage && idx == length)
+ chunk_appendf(tmp, " %s\n", kw->usage);
}
}