@@ -2916,6 +2916,8 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
29162916 int is_last_word = 0 ;
29172917 int (* validator )(struct cli_def * , const char * name , const char * value );
29182918
2919+ if (cli -> buildmode ) cli -> found_optargs = cli -> buildmode -> found_optargs ;
2920+ else cli -> found_optargs = stage -> found_optargs ;
29192921 /*
29202922 * Tab completion and help are *only* allowed at end of string, but we need to process the entire command to know what
29212923 * has already been found. There should be no ambiguities before the 'last' word.
@@ -2960,7 +2962,7 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
29602962 if (stage -> status != CLI_OK ) {
29612963 stage -> error_word = stage -> words [word_idx ];
29622964 cli_reprompt (cli );
2963- return ;
2965+ goto done ;
29642966 }
29652967 } else if (stage -> words [word_idx ] && (oaptr -> flags & (CLI_CMD_OPTIONAL_FLAG | CLI_CMD_OPTIONAL_ARGUMENT )) &&
29662968 !strcmp (oaptr -> name , stage -> words [word_idx ])) {
@@ -2992,7 +2994,7 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
29922994 stage -> error_word = stage -> words [word_idx ];
29932995 stage -> status = CLI_AMBIGUOUS ;
29942996 cli_error (cli , "Ambiguous option/argument for command %s" , stage -> command -> command );
2995- return ;
2997+ goto done ;
29962998 }
29972999
29983000 /*
@@ -3021,7 +3023,7 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
30213023 // If we were 'end-of-word' and looked for completions/help, return to user
30223024 if (called_comphelp ) {
30233025 stage -> status = CLI_OK ;
3024- return ;
3026+ goto done ;
30253027 }
30263028 }
30273029
@@ -3041,7 +3043,7 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
30413043 cli_error (cli , "Optional argument %s requires a value" , stage -> words [word_idx ]);
30423044 stage -> error_word = stage -> words [word_idx ];
30433045 stage -> status = CLI_MISSING_VALUE ;
3044- return ;
3046+ goto done ;
30453047 }
30463048 value = stage -> words [word_idx + 1 ];
30473049 }
@@ -3076,7 +3078,7 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
30763078 cli_reprompt (cli );
30773079 stage -> error_word = stage -> words [word_idx ];
30783080 stage -> status = CLI_ERROR ;
3079- return ;
3081+ goto done ;
30803082 }
30813083 }
30823084 } else {
@@ -3085,20 +3087,20 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
30853087 cli_reprompt (cli );
30863088 stage -> error_word = stage -> words [word_idx ];
30873089 stage -> status = CLI_ERROR ;
3088- return ;
3090+ goto done ;
30893091 }
30903092
30913093 // If this optarg can set the transient mode, then evaluate it if we're not at last word
30923094 if (oaptr -> transient_mode && oaptr -> transient_mode (cli , oaptr -> name , value )) {
30933095 stage -> error_word = stage -> words [word_idx ];
30943096 stage -> status = CLI_ERROR ;
3095- return ;
3097+ goto done ;
30963098 }
30973099
30983100 // Only do buildmode optargs if we're a executing a command, parsing command (stage 0), and this is the last word
30993101 if ((stage -> status == CLI_OK ) && (oaptr -> flags & CLI_CMD_ALLOW_BUILDMODE ) && is_last_word ) {
31003102 stage -> status = cli_int_enter_buildmode (cli , stage , value );
3101- return ;
3103+ goto done ;
31023104 }
31033105
31043106 // Optional flags and arguments can appear multiple times, but true arguments only once. Advance our optarg
@@ -3121,10 +3123,14 @@ static void cli_int_parse_optargs(struct cli_def *cli, struct cli_pipeline_stage
31213123 if (optarg -> flags & CLI_CMD_ARGUMENT ) {
31223124 cli_error (cli , "Incomplete command, missing required argument '%s'" , optarg -> name );
31233125 stage -> status = CLI_MISSING_ARGUMENT ;
3124- return ;
3126+ goto done ;
31253127 }
31263128 }
31273129 }
3130+
3131+ done :
3132+ if (cli -> buildmode ) cli -> buildmode -> found_optargs = cli -> found_optargs ;
3133+ else stage -> found_optargs = cli -> found_optargs ;
31283134 return ;
31293135}
31303136
0 commit comments