From: Tokunori Ikegami Date: Mon, 20 Mar 2023 13:11:22 +0000 (+0900) Subject: util: Introduce argconfig simple helper to check seen condition X-Git-Tag: v2.4~27 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c07430a27d4ae28abbba3a1c41a8aa491a38c3a0;p=users%2Fsagi%2Fnvme-cli.git util: Introduce argconfig simple helper to check seen condition Signed-off-by: Tokunori Ikegami --- diff --git a/nvme.c b/nvme.c index 94bdca7b..c852f69e 100644 --- a/nvme.c +++ b/nvme.c @@ -4700,7 +4700,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, if (err) goto ret; - if (!opts[1].seen) { + if (!argconfig_parse_seen(opts, "namespace-id")) { err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id); if (err < 0) { if (errno != ENOTTY) { @@ -5882,7 +5882,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin if (err) goto ret; - if (!opts[0].seen) { + if (!argconfig_parse_seen(opts, "namespace-id")) { err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id); if (err < 0) { if (errno != ENOTTY) { diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 3edfe450..91c70f1f 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -953,9 +953,10 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd, if (err) return err; - if (opts[0].seen) + if (argconfig_parse_seen(opts, "mode")) err = eol_plp_failure_mode_set(dev, nsid, fid, cfg.mode, - cfg.save, !opts[3].seen); + cfg.save, + !argconfig_parse_seen(opts, "no-uuid")); else err = eol_plp_failure_mode_get(dev, nsid, fid, cfg.sel); diff --git a/util/argconfig.c b/util/argconfig.c index a3554b06..33370439 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -597,3 +597,16 @@ void argconfig_register_help_func(argconfig_help_func * f) } } } + +bool argconfig_parse_seen(struct argconfig_commandline_options *options, + const char *option) +{ + struct argconfig_commandline_options *s; + + for (s = options; s && s->option; s++) { + if (!strcmp(s->option, option)) + return s->seen;; + } + + return false; +} diff --git a/util/argconfig.h b/util/argconfig.h index d1c54221..8f7e7bbe 100644 --- a/util/argconfig.h +++ b/util/argconfig.h @@ -135,4 +135,6 @@ int argconfig_parse_byte(const char *opt, const char *str, unsigned char *val); void argconfig_register_help_func(argconfig_help_func * f); void print_word_wrapped(const char *s, int indent, int start, FILE *stream); +bool argconfig_parse_seen(struct argconfig_commandline_options *options, + const char *option); #endif