From bdca6760fef968586736a291b5b7bd0ad5f62c17 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 12 Mar 2024 20:42:56 +0100 Subject: [PATCH] Fail "define-command -menu" unless a completer is given The "define-command -menu" flag does not do anything unless there is a completer flag. Let's reject it. --- src/commands.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands.cc b/src/commands.cc index 96cd0a2d..c1644f01 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1347,7 +1347,8 @@ void define_command(const ParametersParser& parser, Context& context, const Shel if (parser.get_switch("hidden")) flags = CommandFlags::Hidden; - const Completions::Flags completions_flags = parser.get_switch("menu") ? + const bool menu = (bool)parser.get_switch("menu"); + const Completions::Flags completions_flags = menu ? Completions::Flags::Menu : Completions::Flags::None; const String& commands = parser[1]; @@ -1384,6 +1385,8 @@ void define_command(const ParametersParser& parser, Context& context, const Shel } CommandCompleter completer = parse_completion_switch(parser, completions_flags); + if (menu and not completer) + throw runtime_error("menu switch requires a completion switch"); auto docstring = trim_indent(parser.get_switch("docstring").value_or(StringView{})); cm.register_command(cmd_name, cmd, docstring, desc, flags, CommandHelper{}, std::move(completer));