summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-12-02 06:05:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-12-07 22:17:49 (GMT)
commita02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c (patch)
tree544477a27a6aafe9d797d23e4b6018d11abe26d2 /parse-options.c
parent1e5ce570ca368b97c8e3b238bb0228c5ca41b494 (diff)
downloadgit-a02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c.zip
git-a02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c.tar.gz
git-a02dd4ff7dd79eb6aa39b00c90c293e3c3d10b4c.tar.bz2
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>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/parse-options.c b/parse-options.c
index 67d1adc..9ff9aca 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -288,13 +288,6 @@ static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
for (; options->type != OPTION_END; options++) {
if (!(options->flags & PARSE_OPT_NODASH))
continue;
- if ((options->flags & PARSE_OPT_OPTARG) ||
- !(options->flags & PARSE_OPT_NOARG))
- die("BUG: dashless options don't support arguments");
- if (!(options->flags & PARSE_OPT_NONEG))
- die("BUG: dashless options don't support negation");
- if (options->long_name)
- die("BUG: dashless options can't be long");
if (options->short_name == arg[0] && arg[1] == '\0')
return get_value(p, options, OPT_SHORT);
}
@@ -330,6 +323,13 @@ static void parse_options_check(const struct option *opts)
(opts->flags & PARSE_OPT_OPTARG))
err |= optbug(opts, "uses incompatible flags "
"LASTARG_DEFAULT and OPTARG");
+ if (opts->flags & PARSE_OPT_NODASH &&
+ ((opts->flags & PARSE_OPT_OPTARG) ||
+ !(opts->flags & PARSE_OPT_NOARG) ||
+ !(opts->flags & PARSE_OPT_NONEG) ||
+ opts->long_name))
+ err |= optbug(opts, "uses feature "
+ "not supported for dashless options");
}
if (err)
exit(128);