in src/options.cc [119:160]
error_t Options::parse_arg(int key, char *arg) {
// if it's in the map of expected options
if (opt_map.count(key)) {
// get the option from the opt_map
DiskspdOption& option = opt_map[key];
// check for duplicate args
if (opts.count(option.type)) {
fprintf(stderr, "Option -%c already specified!\n", (char)key);
return EINVAL;
}
// add to map of parsed options
opts[option.type] = key;
// get argument and validate it
if (arg) {
option.arg = std::string(arg);
if ((option.flags & OPT_NUMERIC) && !is_numeric(arg)) {
fprintf(stderr, "Argument to option -%c was invalid!\n", (char)key);
return EINVAL;
} else if ((option.flags & OPT_BYTE_SIZE) && !valid_byte_size(arg)) {
fprintf(stderr, "Argument to option -%c was invalid!\n", (char)key);
return EINVAL;
} else if ((option.flags & OPT_NON_ZERO) &&
(arg[0] == '0' && (arg[1] < '1' || arg[1] > '9'))) {
fprintf(stderr, "Argument to option -%c was invalid!\n", (char)key);
return EINVAL;
} // else do nothing - it will have to be validated by profile.cc
}
} else if (key == ARGP_KEY_ARG) {
// otherwise it's a non-option (a target for diskspd), so push it to the vector
non_opts.push_back(std::string(arg));
} else {
return ARGP_ERR_UNKNOWN;
}
return 0;
}