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 <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/387634
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Paul Luse 2017-11-15 10:18:33 -07:00 committed by Ben Walker
parent ea134c5cbf
commit db26b96fc0

View File

@ -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);
}
/*