From: Karthik Nayak Date: Tue, 10 Mar 2026 12:46:12 GMT Subject: Re: [PATCH v3 1/8] parseopt: extract subcommand handling from parse_options_step() Message-ID: In-Reply-To: Jiamu Sun <39@barroit.sh> writes: [snip] > @@ -990,38 +1017,17 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx, > if (*arg != '-' || !arg[1]) { > if (parse_nodash_opt(ctx, arg, options) == 0) > continue; > - if (!ctx->has_subcommands) { > - if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) > - return PARSE_OPT_NON_OPTION; > - ctx->out[ctx->cpidx++] = ctx->argv[0]; > - continue; > - } > - switch (parse_subcommand(arg, options)) { > - case PARSE_OPT_SUBCOMMAND: > - return PARSE_OPT_SUBCOMMAND; > - case PARSE_OPT_UNKNOWN: > - if (ctx->flags & PARSE_OPT_SUBCOMMAND_OPTIONAL) > - /* > - * arg is neither a short or long > - * option nor a subcommand. Since > - * this command has a default > - * operation mode, we have to treat > - * this arg and all remaining args > - * as args meant to that default > - * operation mode. > - * So we are done parsing. > - */ > - return PARSE_OPT_DONE; > - error(_("unknown subcommand: `%s'"), arg); > - usage_with_options(usagestr, options); > - case PARSE_OPT_COMPLETE: > - case PARSE_OPT_HELP: > - case PARSE_OPT_ERROR: > - case PARSE_OPT_DONE: > - case PARSE_OPT_NON_OPTION: > - /* Impossible. */ > - BUG("parse_subcommand() cannot return these"); > + > + if (ctx->has_subcommands) { > + return handle_subcommand(ctx, arg, options, > + usagestr); > } > + Nit: we try to avoid braces around single statement blocks. > + if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) > + return PARSE_OPT_NON_OPTION; > + > + ctx->out[ctx->cpidx++] = ctx->argv[0]; > + continue; > } > > /* lone -h asks for help */ > -- > 2.53.0