options: show closest match for unknown job option
authorJens Axboe <axboe@fb.com>
Sat, 6 Dec 2014 16:17:52 +0000 (09:17 -0700)
committerJens Axboe <axboe@fb.com>
Sat, 6 Dec 2014 16:17:52 +0000 (09:17 -0700)
Just like we did for the command line options.

Signed-off-by: Jens Axboe <axboe@fb.com>
options.c

index c3c6292733b29f4a59272109eff7eab20fdb5720..98f4b2b04a6638f092ef0f26c1491c65f45e88f6 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3933,6 +3933,27 @@ static char **dup_and_sub_options(char **opts, int num_opts)
        return opts_copy;
 }
 
+static void show_closest_option(const char *name)
+{
+       int best_option, best_distance;
+       int i, distance;
+
+       best_option = -1;
+       best_distance = INT_MAX;
+       i = 0;
+       while (fio_options[i].name) {
+               distance = string_distance(name, fio_options[i].name);
+               if (distance < best_distance) {
+                       best_distance = distance;
+                       best_option = i;
+               }
+               i++;
+       }
+
+       if (best_option != -1)
+               log_err("Did you mean %s?\n", fio_options[best_option].name);
+}
+
 int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
                        int dump_cmdline)
 {
@@ -3968,6 +3989,7 @@ int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
                for (i = 0; i < num_opts; i++) {
                        struct fio_option *o = NULL;
                        int newret = 1;
+
                        if (!opts_copy[i])
                                continue;
 
@@ -3977,9 +3999,10 @@ int fio_options_parse(struct thread_data *td, char **opts, int num_opts,
                                                      td->eo, dump_cmdline);
 
                        ret |= newret;
-                       if (!o)
+                       if (!o) {
                                log_err("Bad option <%s>\n", opts[i]);
-
+                               show_closest_option(opts[i]);
+                       }
                        free(opts_copy[i]);
                        opts_copy[i] = NULL;
                }