Show alias in command help
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 79565754b804ff12880071912b4d1305b15f7c08..f503916de528852135936fb2435543468ed5b256 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -21,18 +21,18 @@ static void show_option_range(struct fio_option *o)
 
 static void show_option_values(struct fio_option *o)
 {
-       const char *msg;
        int i = 0;
 
        do {
-               msg = o->posval[i].ival;
-               if (!msg)
-                       break;
+               const struct value_pair *vp = &o->posval[i];
 
-               if (!i)
-                       printf("%20s: ", "valid values");
+               if (!vp->ival)
+                       break;
 
-               printf("%s,", msg);
+               printf("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
+               if (vp->help)
+                       printf(" %s", vp->help);
+               printf("\n");
                i++;
        } while (i < PARSE_MAX_VP);
 
@@ -197,11 +197,11 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                const struct value_pair *vp;
                int i;
 
-               ret = 1;
                for (i = 0; i < PARSE_MAX_VP; i++) {
                        vp = &o->posval[i];
                        if (!vp->ival || vp->ival[0] == '\0')
                                break;
+                       ret = 1;
                        if (!strncmp(vp->ival, ptr, strlen(vp->ival))) {
                                ret = 0;
                                if (!o->off1)
@@ -257,10 +257,20 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                }
                break;
        }
-       case FIO_OPT_STR_STORE:
+       case FIO_OPT_STR_STORE: {
+               fio_opt_str_fn *fn = o->cb;
+
                cp = td_var(data, o->off1);
                *cp = strdup(ptr);
+               if (fn) {
+                       ret = fn(data, ptr);
+                       if (ret) {
+                               free(*cp);
+                               *cp = NULL;
+                       }
+               }
                break;
+       }
        case FIO_OPT_RANGE: {
                char tmp[128];
                char *p1, *p2;
@@ -369,6 +379,8 @@ static int handle_option(struct fio_option *o, const char *ptr, void *data)
                ptr2 = strchr(ptr, ',');
                if (!ptr2)
                        ptr2 = strchr(ptr, ':');
+               if (!ptr2)
+                       ptr2 = strchr(ptr, '-');
        }
 
        /*
@@ -490,6 +502,9 @@ static void show_option_help(struct fio_option *o)
                "no argument (opt)",
        };
 
+       if (o->alias)
+               printf("%20s: %s\n", "alias", o->alias);
+
        printf("%20s: %s\n", "type", typehelp[o->type]);
        printf("%20s: %s\n", "default", o->def ? o->def : "no default");
        show_option_range(o);
@@ -512,7 +527,8 @@ int show_cmd_help(struct fio_option *options, const char *name)
                int match = 0;
 
                if (name) {
-                       if (!strcmp(name, o->name))
+                       if (!strcmp(name, o->name) ||
+                           (o->alias && !strcmp(name, o->alias)))
                                match = 1;
                        else {
                                unsigned int dist;
@@ -527,9 +543,12 @@ int show_cmd_help(struct fio_option *options, const char *name)
 
                if (show_all || match) {
                        found = 1;
-                       printf("%20s: %s\n", o->name, o->help);
-                       if (show_all)
+                       if (match)
+                               printf("%20s: %s\n", o->name, o->help);
+                       if (show_all) {
+                               printf("%-20s: %s\n", o->name, o->help);
                                continue;
+                       }
                }
 
                if (!match)
@@ -579,7 +598,7 @@ void options_init(struct fio_option *options)
                }
                if (!o->cb && !o->off1)
                        fprintf(stderr, "Option %s: neither cb nor offset given\n", o->name);
-               if (o->type == FIO_OPT_STR)
+               if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE)
                        continue;
                if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4))
                        fprintf(stderr, "Option %s: both cb and offset given\n", o->name);