Re: [PATCH 1/6] parse-options: sanity check PARSE_OPT_NOARG flag
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 1, 2010, 23:36 UTC
- Message-ID
- <7v39qht698.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <4CF4B21B.5030401@gmail.com>
Stephen Boyd <bebarino@gmail.com> writes:
Show 23 quoted lines
> On 11/29/10 18:55, Jonathan Nieder wrote:
>> +static void check_flags(const struct option *opt)
>> +{
>> + switch (opt->type) {
>> + case OPTION_BOOLEAN:
>> + case OPTION_BIT:
>> + case OPTION_NEGBIT:
>> + case OPTION_SET_INT:
>> + case OPTION_SET_PTR:
>> + case OPTION_NUMBER:
>> + break;
>> + default: /* (usually accepts an argument) */
>> + return;
>> + }
>> + if ((opt->flags & (PARSE_OPT_OPTARG | PARSE_OPT_NOARG)) == PARSE_OPT_NOARG)
>> + return;
>> + die("BUG: option '-%c%s' should not accept an argument",
>> + !opt->short_name ? '-' : opt->short_name,
>> + !opt->short_name ? opt->long_name : "");
>> +}
>> +
>
> This check should probably go into parse_options_check()...Very good suggestion---that way we can check and get diagnosis for all the errors, not just dying on the first one.