summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ad7e6e)
raw | patch | inline | side by side (parent: 9ad7e6e)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Mon, 9 Mar 2009 20:57:38 +0000 (21:57 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 Mar 2009 22:32:50 +0000 (15:32 -0700) |
As suggested by Junio, disallow the flags PARSE_OPT_KEEP_UNKNOWN and
PARSE_OPT_STOP_AT_NON_OPTION to be turned on at the same time, as a
value of an unknown option could be mistakenly classified as a
non-option, stopping the parser early. E.g.:
git cmd --known --unknown value arg0 arg1
The parser should have stopped at "arg0", but it already stops at
"value".
This patch makes parse_options() die if the two flags are used in
combination.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
PARSE_OPT_STOP_AT_NON_OPTION to be turned on at the same time, as a
value of an unknown option could be mistakenly classified as a
non-option, stopping the parser early. E.g.:
git cmd --known --unknown value arg0 arg1
The parser should have stopped at "arg0", but it already stops at
"value".
This patch makes parse_options() die if the two flags are used in
combination.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-parse-options.txt | patch | blob | history | |
parse-options.c | patch | blob | history |
diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index 20b44ff9f32df79f64f2513f21777bf591d1c843..e66ca9f70c705841c864196a3a651e04d8156e01 100644 (file)
`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 51e804b3bea3dab71e1df7b9c7db3635025b538e..cf71bcffd2e1e9aeacb44df488b0825f09d54255 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
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 *,