use low match distance for helping, or use ask user to use "help"
This commit is contained in:
25
lib/sl/sl.c
25
lib/sl/sl.c
@@ -443,10 +443,18 @@ osad(const char *s1, const char *s2)
|
|||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will propose a list of command that are almost matching the command
|
||||||
|
* used, if there is no matching, will ask the user to use "help".
|
||||||
|
*
|
||||||
|
* @param cmds command array to use for matching
|
||||||
|
* @param match the command that didn't exists
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
sl_did_you_mean(SL_cmd *cmds, const char *match)
|
sl_did_you_mean(SL_cmd *cmds, const char *match)
|
||||||
{
|
{
|
||||||
int *metrics, best_match = INT_MAX, print = 0;
|
int *metrics, best_match = INT_MAX;
|
||||||
SL_cmd *c;
|
SL_cmd *c;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
@@ -467,14 +475,21 @@ sl_did_you_mean(SL_cmd *cmds, const char *match)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "%s is not a known command, did you mean:", match);
|
/* if match distance is low, propose that for the user */
|
||||||
|
if (best_match < 7) {
|
||||||
|
|
||||||
|
fprintf(stderr, "error: %s is not a known command, did you mean ?\n", match);
|
||||||
for (n = 0; cmds[n].name; n++) {
|
for (n = 0; cmds[n].name; n++) {
|
||||||
if (metrics[n] == best_match) {
|
if (metrics[n] == best_match) {
|
||||||
fprintf(stderr, "%s %s", print ? "," : "", cmds[n].name);
|
fprintf(stderr, "\t%s\n", cmds[n].name);
|
||||||
print = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, " ?\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
fprintf(stderr, "error: %s is not a command, use \"help\" for more list of commands.\n", match);
|
||||||
|
}
|
||||||
|
|
||||||
free(metrics);
|
free(metrics);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user