Subject: Re: [PATCH 02/10] parse-options: clearer reporting of API misuse

From: Jonathan Nieder <[email-masked]>
Date: Wed, 1 Dec 2010 22:57:07 -0600

Jonathan Nieder wrote:

> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -316,24 +323,12 @@ static void check_typos(const char *arg, const struct option *options)
>  
>  static void parse_options_check(const struct option *opts)
>  {
> -	int err = 0;
> -
>  	for (; opts->type != OPTION_END; opts++) {
>  		if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) &&
> -		    (opts->flags & PARSE_OPT_OPTARG)) {
> -			if (opts->long_name) {
> -				error("`--%s` uses incompatible flags "
> -				      "LASTARG_DEFAULT and OPTARG", opts->long_name);
> -			} else {
> -				error("`-%c` uses incompatible flags "
> -				      "LASTARG_DEFAULT and OPTARG", opts->short_name);
> -			}
> -			err |= 1;
> -		}
> +		    (opts->flags & PARSE_OPT_OPTARG))
> +			optbug(opts, "uses incompatible flags "
> +				"LASTARG_DEFAULT and OPTARG");
>  	}
> -
> -	if (err)
> -		exit(129);

Hmph, this is simpler but it does not report all errors any more.
So it would be better to do:

	int err = 0;

	for (; opts->type != OPTION_END; opts++) {
		if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) &&
		    (opts->flags & PARSE_OPT_OPTARG))
			err |= optbug(opts, "uses incompatible flags "
						"LASTARG_DEFAULT and OPTARG");
	}
	if (err)
		exit(128);

Sorry about that.