[PATCH] Add default option values
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 869b3dbf8ba088d3147b0042c74d2618c278d815..102e607ddde58d942e6f2964ebaa50b0410ecfda 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -154,6 +154,11 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
        char **cp;
        int ret = 0, is_time = 0;
 
+       if (!ptr && o->type != FIO_OPT_STR_SET) {
+               fprintf(stderr, "Option %s requires an argument\n", o->name);
+               return 1;
+       }
+
        switch (o->type) {
        case FIO_OPT_STR: {
                fio_opt_str_fn *fn = o->cb;
@@ -175,8 +180,10 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                if (ret)
                        break;
 
-               if (o->max_val && ull > o->max_val)
-                       ull = o->max_val;
+               if (o->maxval && ull > o->maxval)
+                       ull = o->maxval;
+               if (o->minval && ull < o->minval)
+                       ull = o->minval;
 
                if (fn)
                        ret = fn(data, &ull);
@@ -244,8 +251,10 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                if (ret)
                        break;
 
-               if (o->max_val && il > o->max_val)
-                       il = o->max_val;
+               if (o->maxval && il > o->maxval)
+                       il = o->maxval;
+               if (o->minval && il < o->minval)
+                       il = o->minval;
 
                if (fn)
                        ret = fn(data, &il);
@@ -271,7 +280,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                break;
        }
        default:
-               fprintf(stderr, "Bad option type %d\n", o->type);
+               fprintf(stderr, "Bad option type %u\n", o->type);
                ret = 1;
        }
 
@@ -356,3 +365,55 @@ int parse_option(const char *opt, struct fio_option *options, void *data)
        fprintf(stderr, "fio: failed parsing %s\n", opt);
        return 1;
 }
+
+int show_cmd_help(struct fio_option *options, const char *name)
+{
+       int show_all = !strcmp(name, "all");
+       struct fio_option *o = &options[0];
+       const char *typehelp[] = {
+               "string (opt=bla)",
+               "string with possible k/m/g postfix (opt=4k)",
+               "string with range and postfix (opt=1k-4k)",
+               "string with time postfix (opt=10s)",
+               "string (opt=bla)",
+               "string with dual range (opt=1k-4k,4k-8k)",
+               "integer value (opt=100)",
+               "no argument (opt)",
+       };
+       int found = 0;
+
+       while (o->name) {
+               int match = !strcmp(name, o->name);
+
+               if (show_all || match) {
+                       found = 1;
+                       printf("%s: %s\n", o->name, o->help);
+                       if (match) {
+                               printf("type: %s\n", typehelp[o->type]);
+                               if (o->def)
+                                       printf("default: %s\n", o->def);
+                               else
+                                       printf("defaults: no default\n");
+                       }
+               }
+
+               o++;
+       }
+
+       if (found)
+               return 0;
+
+       printf("No such command: %s\n", name);
+       return 1;
+}
+
+void fill_default_options(void *data, struct fio_option *options)
+{
+       struct fio_option *o = &options[0];
+
+       while (o->name) {
+               if (o->def)
+                       handle_option(o, o->def, data);
+               o++;
+       }
+}