cmCMakeHost*Command: Report keyword errors via argument parser results

This commit is contained in:
Brad King
2022-07-19 14:12:51 -04:00
parent 74ec6b63c2
commit 7e4a9afa1a
3 changed files with 12 additions and 12 deletions
@@ -474,7 +474,7 @@ bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
} }
std::string const& key = *args.begin(); std::string const& key = *args.begin();
struct Arguments struct Arguments : public ArgumentParser::ParseResult
{ {
std::string ValueName; std::string ValueName;
bool ValueNames = false; bool ValueNames = false;
@@ -491,19 +491,15 @@ bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
.Bind("SEPARATOR"_s, &Arguments::Separator) .Bind("SEPARATOR"_s, &Arguments::Separator)
.Bind("ERROR_VARIABLE"_s, &Arguments::ErrorVariable); .Bind("ERROR_VARIABLE"_s, &Arguments::ErrorVariable);
std::vector<std::string> invalidArgs; std::vector<std::string> invalidArgs;
std::vector<cm::string_view> keywordsMissingValue;
Arguments const arguments = Arguments const arguments = parser.Parse(args.advance(1), &invalidArgs);
parser.Parse(args.advance(1), &invalidArgs, &keywordsMissingValue);
if (!invalidArgs.empty()) { if (!invalidArgs.empty()) {
status.SetError(cmStrCat("given invalid argument(s) \"", status.SetError(cmStrCat("given invalid argument(s) \"",
cmJoin(invalidArgs, ", "_s), "\".")); cmJoin(invalidArgs, ", "_s), "\"."));
return false; return false;
} }
if (!keywordsMissingValue.empty()) { if (arguments.MaybeReportError(status.GetMakefile())) {
status.SetError(cmStrCat("missing expected value for argument(s) \"", return true;
cmJoin(keywordsMissingValue, ", "_s), "\"."));
return false;
} }
if ((!arguments.ValueName.empty() && if ((!arguments.ValueName.empty() &&
(arguments.ValueNames || arguments.SubKeys)) || (arguments.ValueNames || arguments.SubKeys)) ||
@@ -1,5 +1,7 @@
CMake Error at Registry_BadQuery2.cmake:[0-9]+ \(cmake_host_system_information\): CMake Error at Registry_BadQuery2.cmake:[0-9]+ \(cmake_host_system_information\):
cmake_host_system_information missing expected value for argument\(s\) Error after keyword "VALUE":
"VALUE".
missing required value
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\) CMakeLists.txt:[0-9]+ \(include\)
@@ -1,5 +1,7 @@
CMake Error at Registry_BadView1.cmake:[0-9]+ \(cmake_host_system_information\): CMake Error at Registry_BadView1.cmake:[0-9]+ \(cmake_host_system_information\):
cmake_host_system_information missing expected value for argument\(s\) Error after keyword "VIEW":
"VIEW".
missing required value
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\) CMakeLists.txt:[0-9]+ \(include\)