parse: make suggestions for unknown options

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/init.c b/init.c
index 4f66759..9fbc477 100644
--- a/init.c
+++ b/init.c
@@ -1875,6 +1875,30 @@
 	fio_client_add_cmd_option(client, opt);
 }
 
+static void show_closest_option(const char *name)
+{
+	int best_option, best_distance;
+	int i, distance;
+
+	while (*name == '-')
+		name++;
+
+	best_option = -1;
+	best_distance = INT_MAX;
+	i = 0;
+	while (l_opts[i].name) {
+		distance = string_distance(name, l_opts[i].name);
+		if (distance < best_distance) {
+			best_distance = distance;
+			best_option = i;
+		}
+		i++;
+	}
+
+	if (best_option != -1)
+		log_err("Did you mean %s?\n", l_opts[best_option].name);
+}
+
 int parse_cmd_line(int argc, char *argv[], int client_type)
 {
 	struct thread_data *td = NULL;
@@ -2237,6 +2261,7 @@
 		case '?':
 			log_err("%s: unrecognized option '%s'\n", argv[0],
 							argv[optind - 1]);
+			show_closest_option(argv[optind - 1]);
 		default:
 			do_exit++;
 			exit_val = 1;
diff --git a/parse.c b/parse.c
index 4209647..141f4b2 100644
--- a/parse.c
+++ b/parse.c
@@ -1068,7 +1068,7 @@
  * Option match, levenshtein distance. Handy for not quite remembering what
  * the option name is.
  */
-static int string_distance(const char *s1, const char *s2)
+int string_distance(const char *s1, const char *s2)
 {
 	unsigned int s1_len = strlen(s1);
 	unsigned int s2_len = strlen(s2);
diff --git a/parse.h b/parse.h
index a9d726d..15f2e06 100644
--- a/parse.h
+++ b/parse.h
@@ -95,6 +95,8 @@
 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);
+
 /*
  * Handlers for the options
  */