From 65b9c26fb4b65093587013fef2932c5eadeef9a7 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 26 May 2022 14:15:28 +0200 Subject: [PATCH] complete: Print better error for -x -F -x is a cheesy shortcut for `-rf`, so it conflicts with `-F`. Fixes #8818. --- src/builtins/complete.cpp | 15 +++++++++++++-- tests/checks/complete.fish | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/builtins/complete.cpp b/src/builtins/complete.cpp index 200ab7502..f27eb8272 100644 --- a/src/builtins/complete.cpp +++ b/src/builtins/complete.cpp @@ -170,6 +170,8 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch {L"escape", no_argument, nullptr, opt_escape}, {}}; + bool have_x = false; + int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, nullptr)) != -1) { @@ -177,6 +179,8 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch case 'x': { result_mode.no_files = true; result_mode.requires_param = true; + // Needed to print an error later. + have_x = true; break; } case 'f': { @@ -301,8 +305,15 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch } if (result_mode.no_files && result_mode.force_files) { - streams.err.append_format(BUILTIN_ERR_COMBO2, L"complete", - L"'--no-files' and '--force-files'"); + if (!have_x) { + 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; } diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 30be47359..626da1d55 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -463,3 +463,6 @@ complete -C"a=1 b=2 cmd_with_fancy_completion " # CHECK: 1 complete -C"a=1 b=2 cmd_with_fancy_completion 1 " # CHECK: 2 + +complete -c thing -x -F +# CHECKERR: complete: invalid option combination, '--exclusive' and '--force-files'