fix bool opt parsing

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2025-10-17 15:06:20 -04:00
parent 69f9e726df
commit 36de1e40a2

View File

@ -736,7 +736,7 @@ const struct bch_option *bch2_cmdline_opt_parse(int argc, char *argv[],
return NULL;
char *optstr = strdup(argv[optind] + 2);
optarg = argv[optind + 1];
optarg = NULL;
char *eq = strchr(optstr, '=');
if (eq) {
@ -744,10 +744,6 @@ const struct bch_option *bch2_cmdline_opt_parse(int argc, char *argv[],
optarg = eq + 1;
}
if (!optarg)
optarg = "1";
int optid = bch2_opt_lookup(optstr);
if (optid < 0)
goto noopt;
@ -758,11 +754,11 @@ const struct bch_option *bch2_cmdline_opt_parse(int argc, char *argv[],
optind++;
if (opt->type != BCH_OPT_BOOL) {
if (optarg == argv[optind])
optind++;
} else {
optarg = NULL;
if (!optarg) {
if (opt->type != BCH_OPT_BOOL)
optarg = argv[optind++];
else
optarg = "1";
}
return opt;