From db26b96fc0a2862b2f72fd2ffcf1c274d25a9d68 Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Wed, 15 Nov 2017 10:18:33 -0700 Subject: [PATCH] blobcli: fix issue with command parsing Introduced when bdev was added as a required option, logic problem with command parsing that broke things when in command mode with, for example, providing a bogus option. Change-Id: I067bf2783f572c6d4fa7660691bb90c470744130 Signed-off-by: Paul Luse Reviewed-on: https://review.gerrithub.io/387634 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- examples/blob/cli/blobcli.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/blob/cli/blobcli.c b/examples/blob/cli/blobcli.c index 4557b425bd..587cf3dad1 100644 --- a/examples/blob/cli/blobcli.c +++ b/examples/blob/cli/blobcli.c @@ -972,15 +972,11 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) int op; int cmd_chosen = 0; char resp; - bool cfg_specified = false; - bool bdev_specified = false; while ((op = getopt(argc, argv, "b:c:d:f:hil:m:n:p:r:s:ST:Xx:")) != -1) { switch (op) { case 'b': if (strcmp(cli_context->bdev_name, "") == 0) { - cmd_chosen++; - bdev_specified = true; snprintf(cli_context->bdev_name, BUFSIZE, "%s", optarg); } else { printf("Current setting for -b is: %s\n", cli_context->bdev_name); @@ -989,8 +985,6 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) break; case 'c': if (cli_context->app_started == false) { - cmd_chosen++; - cfg_specified = true; cli_context->config_file = optarg; } else { usage(cli_context, "ERROR: -c option not valid during shell mode.\n"); @@ -1132,8 +1126,8 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) default: usage(cli_context, "ERROR: invalid option\n"); } - /* only a few options can be combined */ - if ((!cfg_specified && !bdev_specified) && cmd_chosen > 1) { + /* only one actual command can be done at a time */ + if (cmd_chosen > 1) { usage(cli_context, "Error: Please choose only one command\n"); } } @@ -1153,7 +1147,7 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) /* in shell mode we'll call getopt multiple times so need to reset its index */ optind = 0; - return (cmd_chosen > 0); + return (cmd_chosen == 1); } /*