]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/nbft: Use common code to parse print flags
authorDaniel Wagner <dwagner@suse.de>
Wed, 14 Jun 2023 12:08:50 +0000 (14:08 +0200)
committerDaniel Wagner <wagi@monom.org>
Wed, 14 Jun 2023 12:34:38 +0000 (14:34 +0200)
Use validate_output_format instead open coding the print flag parsing.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
plugins/nbft/nbft-plugin.c

index 5ea834f948b4224dc3da299ed3a875735f446b90..e8b3fed0917810096f2beba412df41754ac21b97 100644 (file)
@@ -526,7 +526,7 @@ int show_nbft(int argc, char **argv, struct command *cmd, struct plugin *plugin)
        struct list_head nbft_list;
        char *format = "normal";
        char *nbft_path = NBFT_SYSFS_PATH;
-       enum nvme_print_flags flags = -1;
+       enum nvme_print_flags flags;
        int ret;
        bool show_subsys = false, show_hfi = false, show_discovery = false;
 
@@ -543,18 +543,13 @@ int show_nbft(int argc, char **argv, struct command *cmd, struct plugin *plugin)
        if (ret)
                return ret;
 
+       ret = flags = validate_output_format(format);
+       if (ret < 0)
+               return ret;
+
        if (!(show_subsys || show_hfi || show_discovery))
                show_subsys = show_hfi = show_discovery = true;
 
-       if (!strcmp(format, ""))
-               flags = -1;
-       else if (!strcmp(format, "normal"))
-               flags = NORMAL;
-       else if (!strcmp(format, "json"))
-               flags = JSON;
-       else
-               return -EINVAL;
-
        list_head_init(&nbft_list);
        ret = read_nbft_files(&nbft_list, nbft_path);
        if (!ret) {