parse: only print option mismatch help, if the distance is close enough
authorJens Axboe <axboe@fb.com>
Fri, 21 Aug 2015 18:01:29 +0000 (11:01 -0700)
committerJens Axboe <axboe@fb.com>
Fri, 21 Aug 2015 18:01:29 +0000 (11:01 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
init.c
options.c
parse.c
parse.h

diff --git a/init.c b/init.c
index 7261248fd4349f54f128e0656667b2eeaef10777..cdb98c57231066b5e71c7c7ce2636c7870215d15 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1998,7 +1998,7 @@ static void show_closest_option(const char *name)
                i++;
        }
 
-       if (best_option != -1)
+       if (best_option != -1 && string_distance_ok(name, best_distance))
                log_err("Did you mean %s?\n", l_opts[best_option].name);
 }
 
index ed5d37e45c9c83abef8df6d677257e2a8b0aaf88..e040495d23169833a81581e75a58231c6e32baa5 100644 (file)
--- a/options.c
+++ b/options.c
@@ -4093,7 +4093,7 @@ static void show_closest_option(const char *opt)
                i++;
        }
 
-       if (best_option != -1)
+       if (best_option != -1 && string_distance_ok(name, best_distance))
                log_err("Did you mean %s?\n", fio_options[best_option].name);
 
        free(name);
diff --git a/parse.c b/parse.c
index 745056bdc8186e54743d2fb688df926084c91853..3e94c7d577746e251845245ce4fad018b76829ef 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1061,6 +1061,19 @@ int string_distance(const char *s1, const char *s2)
        return i;
 }
 
+/*
+ * Make a guess of whether the distance from 's1' is significant enough
+ * to warrant printing the guess. We set this to a 1/2 match.
+ */
+int string_distance_ok(const char *opt, int distance)
+{
+       size_t len;
+
+       len = strlen(opt);
+       len = (len + 1) / 2;
+       return distance <= len;
+}
+
 static struct fio_option *find_child(struct fio_option *options,
                                     struct fio_option *o)
 {
diff --git a/parse.h b/parse.h
index 264243b22904f68a6181a99dd85ece446a997251..0a813b0fa7852b5d45731246f7d1e9b0905ad2a0 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -97,6 +97,7 @@ extern int check_str_time(const char *p, long long *val, int);
 extern int str_to_float(const char *str, double *val, int is_time);
 
 extern int string_distance(const char *s1, const char *s2);
+extern int string_distance_ok(const char *s1, int dist);
 
 /*
  * Handlers for the options