cmd: arglist: fix iterator not picking up options without parameters

This commit is contained in:
2024-11-19 15:20:11 +00:00
parent dfa817cb9a
commit 726649189b

View File

@@ -399,6 +399,7 @@ static b_status parse_short_opt(struct argv_parser *parser)
break; break;
} }
subcmd = NULL;
opt = b_command_get_option_with_short_name(parser->cmd, flag); opt = b_command_get_option_with_short_name(parser->cmd, flag);
if (!opt) { if (!opt) {
subcmd = b_command_get_subcommand_with_short_name( subcmd = b_command_get_subcommand_with_short_name(
@@ -831,13 +832,15 @@ int b_arglist_iterator_begin(
{ {
memset(it, 0x0, sizeof *it); memset(it, 0x0, sizeof *it);
it->opt_id = B_COMMAND_INVALID_ID;
it->_base.it_ops = &it_ops; it->_base.it_ops = &it_ops;
it->_opt_filter = opt_filter; it->_opt_filter = opt_filter;
it->_arg_filter = arg_filter; it->_arg_filter = arg_filter;
b_btree_iterator_begin(&args->list_options, &it->_opt_it); b_btree_iterator_begin(&args->list_options, &it->_opt_it);
struct b_arglist_option *opt; struct b_arglist_option *opt = NULL;
struct b_arglist_value *val; struct b_arglist_value *val = NULL;
while (1) { while (1) {
if (!b_btree_iterator_is_valid(&it->_opt_it)) { if (!b_btree_iterator_is_valid(&it->_opt_it)) {
@@ -856,6 +859,10 @@ int b_arglist_iterator_begin(
b_btree_iterator_begin(&opt->opt_values, &it->_arg_it); b_btree_iterator_begin(&opt->opt_values, &it->_arg_it);
while (1) { while (1) {
if (!b_btree_iterator_is_valid(&it->_arg_it)) { if (!b_btree_iterator_is_valid(&it->_arg_it)) {
if (arg_filter == B_COMMAND_INVALID_ID) {
break;
}
val = NULL; val = NULL;
return -1; return -1;
} }
@@ -901,6 +908,7 @@ bool b_arglist_iterator_next(struct b_arglist_iterator *it)
opt = advance_to_next_opt(it); opt = advance_to_next_opt(it);
if (!opt) { if (!opt) {
it->value = NULL; it->value = NULL;
it->opt_id = B_COMMAND_INVALID_ID;
return false; return false;
} }
@@ -910,5 +918,5 @@ bool b_arglist_iterator_next(struct b_arglist_iterator *it)
bool b_arglist_iterator_is_valid(const struct b_arglist_iterator *it) bool b_arglist_iterator_is_valid(const struct b_arglist_iterator *it)
{ {
return it->value != NULL; return it->opt_id != B_COMMAND_INVALID_ID || it->value != NULL;
} }