From 3701636d7d8e8c60b27a54f32a94ede6e15b0380 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 21 Aug 2015 11:01:29 -0700 Subject: [PATCH] parse: only print option mismatch help, if the distance is close enough Signed-off-by: Jens Axboe --- init.c | 2 +- options.c | 2 +- parse.c | 13 +++++++++++++ parse.h | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index 7261248f..cdb98c57 100644 --- 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); } diff --git a/options.c b/options.c index ed5d37e4..e040495d 100644 --- 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 745056bd..3e94c7d5 100644 --- 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 264243b2..0a813b0f 100644 --- 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 -- 2.25.1