Subject: Re: [PATCH v2 09/20] parse-options: add support for parsing subcommands

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 19 Aug 2022 21:03:27 +0200

On Fri, Aug 19 2022, SZEDER Gábor wrote:

> @@ -885,7 +977,14 @@ int parse_options(int argc, const char **argv,
>  	case PARSE_OPT_COMPLETE:
>  		exit(0);
>  	case PARSE_OPT_NON_OPTION:
> +	case PARSE_OPT_SUBCOMMAND:
> +		break;

This amounts to the same behavior, because...

>  	case PARSE_OPT_DONE:
> +		if (ctx.has_subcommands &&
> +		    !(flags & PARSE_OPT_SUBCOMMAND_OPTIONAL)) {
> +			error(_("need a subcommand"));
> +			usage_with_options(usagestr, options);
> +		}
>  		break;

...AFAICT we won't have PARSE_OPT_NON_OPTION *and* ctx.has_subcommands,
but it's really confusing that before we'd fall through from
PARSE_OPT_NON_OPTION to PARSE_OPT_DONE, but now we don't.'