summaryrefslogtreecommitdiff
path: root/Source/cmCMakePathCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-19 14:29:43 -0400
committerBrad King <brad.king@kitware.com>2022-07-22 10:32:25 -0400
commit8a18e82e9581bd490253c1b2531c2c5e70c5d62b (patch)
tree365809519e39042a0aeea962089e75e642ec227b /Source/cmCMakePathCommand.cxx
parent7e4a9afa1a0eaf059e5704920ef82647dad79377 (diff)
downloadcmake-8a18e82e9581bd490253c1b2531c2c5e70c5d62b.tar.gz
cmCMakePathCommand: Report keyword errors via argument parser results
Diffstat (limited to 'Source/cmCMakePathCommand.cxx')
-rw-r--r--Source/cmCMakePathCommand.cxx66
1 files changed, 31 insertions, 35 deletions
diff --git a/Source/cmCMakePathCommand.cxx b/Source/cmCMakePathCommand.cxx
index e604ed1c4c..b955bcf287 100644
--- a/Source/cmCMakePathCommand.cxx
+++ b/Source/cmCMakePathCommand.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakePathCommand.h"
-#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
@@ -44,14 +43,12 @@ public:
}
template <int Advance = 2>
- Result Parse(
- std::vector<std::string> const& args,
- std::vector<cm::string_view>* keywordsMissingValue = nullptr) const
+ Result Parse(std::vector<std::string> const& args) const
{
this->Inputs.clear();
return this->cmArgumentParser<Result>::Parse(
- cmMakeRange(args).advance(Advance), &this->Inputs, keywordsMissingValue);
+ cmMakeRange(args).advance(Advance), &this->Inputs);
}
const std::vector<std::string>& GetInputs() const { return this->Inputs; }
@@ -82,28 +79,13 @@ public:
template <int Advance = 2>
Result Parse(std::vector<std::string> const& args) const
{
- this->KeywordsMissingValue.clear();
-
return this->CMakePathArgumentParser<Result>::template Parse<Advance>(
- args, &this->KeywordsMissingValue);
- }
-
- const std::vector<cm::string_view>& GetKeywordsMissingValue() const
- {
- return this->KeywordsMissingValue;
+ args);
}
bool checkOutputVariable(const Result& arguments,
cmExecutionStatus& status) const
{
- if (std::find(this->GetKeywordsMissingValue().begin(),
- this->GetKeywordsMissingValue().end(),
- "OUTPUT_VARIABLE"_s) !=
- this->GetKeywordsMissingValue().end()) {
- status.SetError("OUTPUT_VARIABLE requires an argument.");
- return false;
- }
-
if (arguments.Output && arguments.Output->empty()) {
status.SetError("Invalid name for output variable.");
return false;
@@ -111,12 +93,9 @@ public:
return true;
}
-
-private:
- mutable std::vector<cm::string_view> KeywordsMissingValue;
};
-struct OutputVariable
+struct OutputVariable : public ArgumentParser::ParseResult
{
cm::optional<std::string> Output;
};
@@ -288,6 +267,9 @@ bool HandleAppendCommand(std::vector<std::string> const& args,
const auto arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -310,6 +292,9 @@ bool HandleAppendStringCommand(std::vector<std::string> const& args,
const auto arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -337,6 +322,9 @@ bool HandleRemoveFilenameCommand(std::vector<std::string> const& args,
const auto arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -367,6 +355,9 @@ bool HandleReplaceFilenameCommand(std::vector<std::string> const& args,
const auto arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -394,7 +385,7 @@ bool HandleReplaceFilenameCommand(std::vector<std::string> const& args,
bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
- struct Arguments
+ struct Arguments : public ArgumentParser::ParseResult
{
cm::optional<std::string> Output;
bool LastOnly = false;
@@ -406,6 +397,9 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
Arguments const arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -437,7 +431,7 @@ bool HandleRemoveExtensionCommand(std::vector<std::string> const& args,
bool HandleReplaceExtensionCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
- struct Arguments
+ struct Arguments : public ArgumentParser::ParseResult
{
cm::optional<std::string> Output;
bool LastOnly = false;
@@ -449,6 +443,9 @@ bool HandleReplaceExtensionCommand(std::vector<std::string> const& args,
Arguments const arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -486,6 +483,9 @@ bool HandleNormalPathCommand(std::vector<std::string> const& args,
const auto arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -514,7 +514,7 @@ bool HandleTransformPathCommand(
const std::string& base)>& transform,
bool normalizeOption = false)
{
- struct Arguments
+ struct Arguments : public ArgumentParser::ParseResult
{
cm::optional<std::string> Output;
cm::optional<std::string> BaseDirectory;
@@ -529,6 +529,9 @@ bool HandleTransformPathCommand(
Arguments arguments = parser.Parse(args);
+ if (arguments.MaybeReportError(status.GetMakefile())) {
+ return true;
+ }
if (!parser.checkOutputVariable(arguments, status)) {
return false;
}
@@ -538,13 +541,6 @@ bool HandleTransformPathCommand(
return false;
}
- if (std::find(parser.GetKeywordsMissingValue().begin(),
- parser.GetKeywordsMissingValue().end(), "BASE_DIRECTORY"_s) !=
- parser.GetKeywordsMissingValue().end()) {
- status.SetError("BASE_DIRECTORY requires an argument.");
- return false;
- }
-
std::string baseDirectory;
if (arguments.BaseDirectory) {
baseDirectory = *arguments.BaseDirectory;