summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9a8531e)
raw | patch | inline | side by side (parent: 9a8531e)
author | Pierre Habouzit <madcoder@debian.org> | |
Tue, 9 Jun 2009 08:23:44 +0000 (10:23 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 10 Jun 2009 15:41:03 +0000 (08:41 -0700) |
It only searches for now for the dreaded LASTARG_DEFAULT | OPTARG
combination, but can be extended to check for any other forbidden
combination.
Options are checked each time we call parse_options_start.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
combination, but can be extended to check for any other forbidden
combination.
Options are checked each time we call parse_options_start.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
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 b85cab2466244ec3c8ea97dc0882c2971e7b8061..79de18b37eb1aa96d2f25963b7f7cc2a08977846 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
}
}
+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;
+ }
+ }
+
+ if (err)
+ exit(129);
+}
+
void parse_options_start(struct parse_opt_ctx_t *ctx,
int argc, const char **argv, const char *prefix,
int flags)
{
int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
+ parse_options_check(options);
+
/* we must reset ->opt, unknown short option leave it dangling */
ctx->opt = NULL;