]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
util: Introduce argconfig simple helper to check seen condition
authorTokunori Ikegami <ikegami.t@gmail.com>
Mon, 20 Mar 2023 13:11:22 +0000 (22:11 +0900)
committerDaniel Wagner <wagi@monom.org>
Tue, 21 Mar 2023 15:57:58 +0000 (16:57 +0100)
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme.c
plugins/ocp/ocp-nvme.c
util/argconfig.c
util/argconfig.h

diff --git a/nvme.c b/nvme.c
index 94bdca7bf35f3b5632a36cb48f3e97a5b892d11a..c852f69ea2d7cd22edae3fffb40a0ce4ca36fc98 100644 (file)
--- 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) {
index 3edfe450b9ff3c896ced0010102b008bba3e9d35..91c70f1faf02fa70704ebbdd954681aa812d0961 100644 (file)
@@ -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);
 
index a3554b06cf6a40e659d9e502507bcbc862a41d0f..333704392b2803ec04e8d0daf64fbb212f673aac 100644 (file)
@@ -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;
+}
index d1c54221e52b7673addb613118363b0de197c697..8f7e7bbefa755d5915e529774fb17729833d969e 100644 (file)
@@ -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