1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmSubcommandTable.h"
7 #include "cmExecutionStatus.h"
8 #include "cmStringAlgorithms.h"
10 cmSubcommandTable::cmSubcommandTable(std::initializer_list<InitElem> init)
11 : Impl(init.begin(), init.end())
13 std::sort(this->Impl.begin(), this->Impl.end(),
14 [](Elem const& left, Elem const& right) {
15 return left.first < right.first;
19 bool cmSubcommandTable::operator()(cm::string_view key,
20 std::vector<std::string> const& args,
21 cmExecutionStatus& status) const
23 auto const it = std::lower_bound(
24 this->Impl.begin(), this->Impl.end(), key,
25 [](Elem const& elem, cm::string_view k) { return elem.first < k; });
26 if (it != this->Impl.end() && it->first == key) {
27 return it->second(args, status);
29 status.SetError(cmStrCat("does not recognize sub-command ", key));