summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a02dd4f)
raw | patch | inline | side by side (parent: a02dd4f)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Thu, 2 Dec 2010 06:08:57 +0000 (00:08 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 7 Dec 2010 22:19:10 +0000 (14:19 -0800) |
Some option types cannot use an argument --- boolean options that
would set a bit or flag or increment a counter, for example. If
configured in the flag word to accept an argument anyway, the result
is an argument that is advertised in "program -h" output only to be
rejected by parse-options::get_value.
Luckily all current users of these option types use PARSE_OPT_NOARG
and do not use PARSE_OPT_OPTARG. Add a check to ensure that that
remains true. The check is run once for each invocation of
parse_option_start().
Improved-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
would set a bit or flag or increment a counter, for example. If
configured in the flag word to accept an argument anyway, the result
is an argument that is advertised in "program -h" output only to be
rejected by parse-options::get_value.
Luckily all current users of these option types use PARSE_OPT_NOARG
and do not use PARSE_OPT_OPTARG. Add a check to ensure that that
remains true. The check is run once for each invocation of
parse_option_start().
Improved-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index 9ff9acaabfb77541675045916a9efe2ee722dfc4..79c56f32f92acc2dc28694f8d8bbcd0b59c3ebba 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
opts->long_name))
err |= optbug(opts, "uses feature "
"not supported for dashless options");
+ switch (opts->type) {
+ case OPTION_BOOLEAN:
+ case OPTION_BIT:
+ case OPTION_NEGBIT:
+ case OPTION_SET_INT:
+ case OPTION_SET_PTR:
+ case OPTION_NUMBER:
+ if ((opts->flags & PARSE_OPT_OPTARG) ||
+ !(opts->flags & PARSE_OPT_NOARG))
+ err |= optbug(opts, "should not accept an argument");
+ default:
+ ; /* ok. (usually accepts an argument) */
+ }
}
if (err)
exit(128);