mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
complete: Print better error for -x -F
-x is a cheesy shortcut for `-rf`, so it conflicts with `-F`. Fixes #8818.
This commit is contained in:
parent
be781e9144
commit
65b9c26fb4
@ -170,6 +170,8 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
|
|||||||
{L"escape", no_argument, nullptr, opt_escape},
|
{L"escape", no_argument, nullptr, opt_escape},
|
||||||
{}};
|
{}};
|
||||||
|
|
||||||
|
bool have_x = false;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) {
|
||||||
@ -177,6 +179,8 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
|
|||||||
case 'x': {
|
case 'x': {
|
||||||
result_mode.no_files = true;
|
result_mode.no_files = true;
|
||||||
result_mode.requires_param = true;
|
result_mode.requires_param = true;
|
||||||
|
// Needed to print an error later.
|
||||||
|
have_x = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'f': {
|
case 'f': {
|
||||||
@ -301,8 +305,15 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result_mode.no_files && result_mode.force_files) {
|
if (result_mode.no_files && result_mode.force_files) {
|
||||||
streams.err.append_format(BUILTIN_ERR_COMBO2, L"complete",
|
if (!have_x) {
|
||||||
L"'--no-files' and '--force-files'");
|
streams.err.append_format(BUILTIN_ERR_COMBO2, L"complete",
|
||||||
|
L"'--no-files' and '--force-files'");
|
||||||
|
} else {
|
||||||
|
// The reason for us not wanting files is `-x`,
|
||||||
|
// which is short for `-rf`.
|
||||||
|
streams.err.append_format(BUILTIN_ERR_COMBO2, L"complete",
|
||||||
|
L"'--exclusive' and '--force-files'");
|
||||||
|
}
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,3 +463,6 @@ complete -C"a=1 b=2 cmd_with_fancy_completion "
|
|||||||
# CHECK: 1
|
# CHECK: 1
|
||||||
complete -C"a=1 b=2 cmd_with_fancy_completion 1 "
|
complete -C"a=1 b=2 cmd_with_fancy_completion 1 "
|
||||||
# CHECK: 2
|
# CHECK: 2
|
||||||
|
|
||||||
|
complete -c thing -x -F
|
||||||
|
# CHECKERR: complete: invalid option combination, '--exclusive' and '--force-files'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user