From 726649189b21f7973d0a4f241f55974e31b8ec66 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 19 Nov 2024 15:20:11 +0000 Subject: [PATCH] cmd: arglist: fix iterator not picking up options without parameters --- cmd/arglist.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/arglist.c b/cmd/arglist.c index cb2a0eb..8a868c7 100644 --- a/cmd/arglist.c +++ b/cmd/arglist.c @@ -399,6 +399,7 @@ static b_status parse_short_opt(struct argv_parser *parser) break; } + subcmd = NULL; opt = b_command_get_option_with_short_name(parser->cmd, flag); if (!opt) { subcmd = b_command_get_subcommand_with_short_name( @@ -831,13 +832,15 @@ int b_arglist_iterator_begin( { memset(it, 0x0, sizeof *it); + it->opt_id = B_COMMAND_INVALID_ID; + it->_base.it_ops = &it_ops; it->_opt_filter = opt_filter; it->_arg_filter = arg_filter; b_btree_iterator_begin(&args->list_options, &it->_opt_it); - struct b_arglist_option *opt; - struct b_arglist_value *val; + struct b_arglist_option *opt = NULL; + struct b_arglist_value *val = NULL; while (1) { 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); while (1) { if (!b_btree_iterator_is_valid(&it->_arg_it)) { + if (arg_filter == B_COMMAND_INVALID_ID) { + break; + } + val = NULL; return -1; } @@ -901,6 +908,7 @@ bool b_arglist_iterator_next(struct b_arglist_iterator *it) opt = advance_to_next_opt(it); if (!opt) { it->value = NULL; + it->opt_id = B_COMMAND_INVALID_ID; 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) { - return it->value != NULL; + return it->opt_id != B_COMMAND_INVALID_ID || it->value != NULL; }