parse-options: do not infer PARSE_OPT_NOARG from option type
Simplify the "takes no value" error path by relying on PARSE_OPT_NOARG being set correctly. That is: - if the PARSE_OPT_NOARG flag is set, reject --opt=value regardless of the option type; - if the PARSE_OPT_NOARG flag is unset, accept --opt=value regardless of the option type. This way, the accepted usage more closely matches the usage advertised with --help-all. No functional change intended, since the NOARG flag is only used with "boolean-only" option types in existing parse_options callers. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Dec 1, 2010 at 17:30 UTC
c1f4ec9ef45232d6dbdea4c417a9d41eb8ad7f4f
1 file changed
+2
-17
parse-options.c
+2
-17
@@ -62,23 +62,8 @@ static int get_value(struct parse_opt_ctx_t *p,
62
return opterror(opt, "takes no value", flags);
63
if (unset && (opt->flags & PARSE_OPT_NONEG))
64
return opterror(opt, "isn't available", flags);
65
-
66
- if (!(flags & OPT_SHORT) && p->opt) {
67
- switch (opt->type) {
68
- case OPTION_CALLBACK:
69
- if (!(opt->flags & PARSE_OPT_NOARG))
70
- break;
71
- /* FALLTHROUGH */
72
- case OPTION_BOOLEAN:
73
- case OPTION_BIT:
74
- case OPTION_NEGBIT:
75
- case OPTION_SET_INT:
76
- case OPTION_SET_PTR:
77
- return opterror(opt, "takes no value", flags);
78
- default:
79
- break;
80
- }
81
- }
65
+ if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
66
+ return opterror(opt, "takes no value", flags);
67
68
switch (opt->type) {
69
case OPTION_BIT: