X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=parse-options.c;h=79de18b37eb1aa96d2f25963b7f7cc2a08977846;hb=cb9d398;hp=b85cab2466244ec3c8ea97dc0882c2971e7b8061;hpb=9831b370b5e50b81faf47d858cd8c6e9e2200204;p=git.git diff --git a/parse-options.c b/parse-options.c index b85cab246..79de18b37 100644 --- a/parse-options.c +++ b/parse-options.c @@ -306,6 +306,28 @@ static void check_typos(const char *arg, const struct option *options) } } +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) @@ -331,6 +353,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, { 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;