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:
parent
ea134c5cbf
commit
db26b96fc0
@ -972,15 +972,11 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context)
|
|||||||
int op;
|
int op;
|
||||||
int cmd_chosen = 0;
|
int cmd_chosen = 0;
|
||||||
char resp;
|
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) {
|
while ((op = getopt(argc, argv, "b:c:d:f:hil:m:n:p:r:s:ST:Xx:")) != -1) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strcmp(cli_context->bdev_name, "") == 0) {
|
if (strcmp(cli_context->bdev_name, "") == 0) {
|
||||||
cmd_chosen++;
|
|
||||||
bdev_specified = true;
|
|
||||||
snprintf(cli_context->bdev_name, BUFSIZE, "%s", optarg);
|
snprintf(cli_context->bdev_name, BUFSIZE, "%s", optarg);
|
||||||
} else {
|
} else {
|
||||||
printf("Current setting for -b is: %s\n", cli_context->bdev_name);
|
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;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (cli_context->app_started == false) {
|
if (cli_context->app_started == false) {
|
||||||
cmd_chosen++;
|
|
||||||
cfg_specified = true;
|
|
||||||
cli_context->config_file = optarg;
|
cli_context->config_file = optarg;
|
||||||
} else {
|
} else {
|
||||||
usage(cli_context, "ERROR: -c option not valid during shell mode.\n");
|
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:
|
default:
|
||||||
usage(cli_context, "ERROR: invalid option\n");
|
usage(cli_context, "ERROR: invalid option\n");
|
||||||
}
|
}
|
||||||
/* only a few options can be combined */
|
/* only one actual command can be done at a time */
|
||||||
if ((!cfg_specified && !bdev_specified) && cmd_chosen > 1) {
|
if (cmd_chosen > 1) {
|
||||||
usage(cli_context, "Error: Please choose only one command\n");
|
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 */
|
/* in shell mode we'll call getopt multiple times so need to reset its index */
|
||||||
optind = 0;
|
optind = 0;
|
||||||
return (cmd_chosen > 0);
|
return (cmd_chosen == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user