parser: match on length of argument, not potential value
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 785d5699857963bcc48ee65db160b7cb4336f0e2..869bcdad4cf2bf43ae6dc2bf8b46a0c1362e0339 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -299,7 +299,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                        if (!vp->ival || vp->ival[0] == '\0')
                                continue;
                        all_skipped = 0;
-                       if (!strncmp(vp->ival, ptr, strlen(vp->ival))) {
+                       if (!strncmp(vp->ival, ptr, strlen(ptr))) {
                                ret = 0;
                                if (o->roff1) {
                                        if (vp->or)
@@ -837,7 +837,7 @@ static void print_option(struct fio_option *o)
 int show_cmd_help(struct fio_option *options, const char *name)
 {
        struct fio_option *o, *closest;
-       unsigned int best_dist;
+       unsigned int best_dist = -1U;
        int found = 0;
        int show_all = 0;
 
@@ -890,7 +890,12 @@ int show_cmd_help(struct fio_option *options, const char *name)
                return 0;
 
        printf("No such command: %s", name);
-       if (closest) {
+
+       /*
+        * Only print an appropriately close option, one where the edit
+        * distance isn't too big. Otherwise we get crazy matches.
+        */
+       if (closest && best_dist < 3) {
                printf(" - showing closest match\n");
                printf("%20s: %s\n", closest->name, closest->help);
                show_option_help(closest, stdout);