Re: [PATCH 02/10] parse-options: clearer reporting of API misuse
From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:50:09
Jonathan Nieder wrote:
quoted hunk ↗ jump to hunk
--- 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.