summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b22939a)
raw | patch | inline | side by side (parent: b22939a)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 3 Mar 2012 11:00:29 +0000 (12:00 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 5 Mar 2012 02:28:59 +0000 (18:28 -0800) |
The user specifies a long option but forgets to type the second
leading dash, we currently detect and report that fact if its first
letter is a valid short option. This is done for safety, to avoid
ambiguity between short options (and their arguments) and a long
option with a missing dash.
This diagnostic message is also helpful for long options whose first
letter is not a valid short option, however. Print it in that case,
too, as a courtesy.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
leading dash, we currently detect and report that fact if its first
letter is a valid short option. This is done for safety, to avoid
ambiguity between short options (and their arguments) and a long
option with a missing dash.
This diagnostic message is also helpful for long options whose first
letter is not a valid short option, however. Print it in that case,
too, as a courtesy.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c | patch | blob | history | |
t/t0040-parse-options.sh | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index 190899611ef9f53a0bc5dc7b1a7f419350a301be..850cfa78c9b7bbcd1cb8504453f60fd15b8ceebb 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
case -1:
return parse_options_usage(ctx, usagestr, options, 1);
case -2:
+ if (ctx->opt)
+ check_typos(arg + 1, options);
goto unknown;
}
if (ctx->opt)
index a44bcb9b3983fa2ba3bc9182702e309577bfc441..e3f354a45e382dbaa9de4557aa9310fa21eb626b 100755 (executable)
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
test_cmp typo.err output.err
'
+cat > typo.err << EOF
+error: did you mean \`--ambiguous\` (with two dashes ?)
+EOF
+
+test_expect_success 'detect possible typos' '
+ test_must_fail test-parse-options -ambiguous > output 2> output.err &&
+ test ! -s output &&
+ test_cmp typo.err output.err
+'
+
cat > expect <<EOF
boolean: 0
integer: 0