@matheusbsbs / matheus-bagliano / commits / a02dd4ff7d
Fork 0

parse-options: move NODASH sanity checks to parse_options_check

A dashless switch (like '(' passed to 'git grep') cannot be negated, cannot be attached to an argument, and cannot have a long form. Currently parse-options runs the related sanity checks when the dashless option is used; better to always check them at the start of option parsing, so mistakes can be caught more quickly. The error message at the new call site is less specific about the nature of the error, for simplicity. On the other hand, it prints which switch was problematic. Before: fatal: BUG: dashless options can't be long After: error: BUG: switch '(' uses feature not supported for dashless options Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Dec 2, 2010 at 00:05 UTC a02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c
1 file changed +7 -7
parse-options.c
+7 -7
@@ -288,13 +288,6 @@ static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
288 for (; options->type != OPTION_END; options++) {
289 if (!(options->flags & PARSE_OPT_NODASH))
290 continue;
291 - if ((options->flags & PARSE_OPT_OPTARG) ||
292 - !(options->flags & PARSE_OPT_NOARG))
293 - die("BUG: dashless options don't support arguments");
294 - if (!(options->flags & PARSE_OPT_NONEG))
295 - die("BUG: dashless options don't support negation");
296 - if (options->long_name)
297 - die("BUG: dashless options can't be long");
291 if (options->short_name == arg[0] && arg[1] == '\0')
292 return get_value(p, options, OPT_SHORT);
293 }
@@ -330,6 +323,13 @@ static void parse_options_check(const struct option *opts)
323 (opts->flags & PARSE_OPT_OPTARG))
324 err |= optbug(opts, "uses incompatible flags "
325 "LASTARG_DEFAULT and OPTARG");
326 + if (opts->flags & PARSE_OPT_NODASH &&
327 + ((opts->flags & PARSE_OPT_OPTARG) ||
328 + !(opts->flags & PARSE_OPT_NOARG) ||
329 + !(opts->flags & PARSE_OPT_NONEG) ||
330 + opts->long_name))
331 + err |= optbug(opts, "uses feature "
332 + "not supported for dashless options");
333 }
334 if (err)
335 exit(128);