diff options
-rw-r--r-- | Documentation/technical/api-parse-options.txt | 3 | ||||
-rw-r--r-- | parse-options.c | 3 |
2 files changed, 5 insertions, 1 deletions
diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index 20b44ff9f3..e66ca9f70c 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -96,7 +96,8 @@ Flags are the bitwise-or of: `PARSE_OPT_STOP_AT_NON_OPTION` is set, the second argument in `--unknown value` will be mistakenly interpreted as a non-option, not as a value belonging to the unknown option, - stopping the parser early. + the parser early. That's why parse_options() errors out if + both options are set. `PARSE_OPT_NO_INTERNAL_HELP`:: By default, parse_options() handles `-h`, `--help` and diff --git a/parse-options.c b/parse-options.c index 51e804b3be..cf71bcffd2 100644 --- a/parse-options.c +++ b/parse-options.c @@ -244,6 +244,9 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->out = argv; ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); ctx->flags = flags; + if ((flags & PARSE_OPT_KEEP_UNKNOWN) && + (flags & PARSE_OPT_STOP_AT_NON_OPTION)) + die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together"); } static int usage_with_options_internal(const char * const *, |