зеркало из https://github.com/microsoft/git.git
parse-options: typo check for unknown switches
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>
This commit is contained in:
Родитель
b22939a286
Коммит
38916c5b47
|
@ -393,6 +393,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
|
||||||
case -1:
|
case -1:
|
||||||
return parse_options_usage(ctx, usagestr, options, 1);
|
return parse_options_usage(ctx, usagestr, options, 1);
|
||||||
case -2:
|
case -2:
|
||||||
|
if (ctx->opt)
|
||||||
|
check_typos(arg + 1, options);
|
||||||
goto unknown;
|
goto unknown;
|
||||||
}
|
}
|
||||||
if (ctx->opt)
|
if (ctx->opt)
|
||||||
|
|
|
@ -236,6 +236,16 @@ test_expect_success 'detect possible typos' '
|
||||||
test_cmp typo.err output.err
|
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
|
cat > expect <<EOF
|
||||||
boolean: 0
|
boolean: 0
|
||||||
integer: 0
|
integer: 0
|
||||||
|
|
Загрузка…
Ссылка в новой задаче