summaryrefslogtreecommitdiff
path: root/src/commands.cc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-03-12 20:42:56 +0100
committerMaxime Coste <mawww@kakoune.org>2024-03-15 21:54:26 +1100
commitbdca6760fef968586736a291b5b7bd0ad5f62c17 (patch)
treea357e627263129f30fb246bef5f51418e095bfe8 /src/commands.cc
parent4d8de48ec33aa9ca097d33bf84f8d7cdffeecaee (diff)
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.
Diffstat (limited to 'src/commands.cc')
-rw-r--r--src/commands.cc5
1 files changed, 4 insertions, 1 deletions
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));