mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
cmSubcommandTable: Implement closest string for invalid subcommand
This commit is contained in:
1 parent
8e91f7aa9b
commit
859a40b291
6 files changed
+20
-1
No files matched your search
@@ -17,6 +17,7 @@ skip =
|
||||
Source/kwsys/*,
|
||||
Tests/RunCMake/CPack/tests/DMG_SLA/German.*,
|
||||
Tests/RunCMake/CommandLine/RunCMakeTest.cmake,
|
||||
Tests/RunCMake/list/InvalidSubcommandDidYouMean*,
|
||||
Tests/RunCMake/ParseImplicitData/*.input,
|
||||
Tests/RunCMake/cmake_language/call_typo_function.cmake,
|
||||
Tests/StringFileTest/test.utf8,
|
||||
|
||||
@@ -26,6 +26,17 @@ bool cmSubcommandTable::operator()(cm::string_view key,
|
||||
if (it != this->Impl.end() && it->first == key) {
|
||||
return it->second(args, status);
|
||||
}
|
||||
status.SetError(cmStrCat("does not recognize sub-command ", key));
|
||||
std::string error = cmStrCat("does not recognize sub-command ", key);
|
||||
std::vector<std::string> candidates;
|
||||
candidates.reserve(this->Impl.size());
|
||||
for (Elem const& elem : this->Impl) {
|
||||
candidates.emplace_back(elem.first);
|
||||
}
|
||||
std::string const suggestion = cmFindClosestString(key, candidates);
|
||||
if (!suggestion.empty()) {
|
||||
error =
|
||||
cmStrCat(std::move(error), ". Did you mean: \"", suggestion, "\"?");
|
||||
}
|
||||
status.SetError(error);
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,4 @@
|
||||
^CMake Error at InvalidSubcommandDidYouMean\.cmake:1 \(list\):
|
||||
list does not recognize sub-command APEND\. Did you mean: "APPEND"\?
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:3 \(include\)$
|
||||
@@ -0,0 +1 @@
|
||||
list(APEND mylist a)
|
||||
@@ -7,6 +7,7 @@ run_cmake(EmptyInsert-1)
|
||||
|
||||
run_cmake(NoArguments)
|
||||
run_cmake(InvalidSubcommand)
|
||||
run_cmake(InvalidSubcommandDidYouMean)
|
||||
|
||||
run_cmake(FILTER-REGEX-InvalidRegex)
|
||||
run_cmake(GET-InvalidIndex)
|
||||
|
||||
Reference in new issue
Block a user