summaryrefslogtreecommitdiff
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-06 11:45:57 -0400
committerBrad King <brad.king@kitware.com>2022-07-07 09:49:04 -0400
commitf46b2e914256322fc8d33b425ec01e9d9c1496ba (patch)
treec52e8e524354fa7c7248ea5ed14802e470a6933b /Source/cmFileCommand.cxx
parente6d1e29ffa6bd3141a769d1281f3407ed0774139 (diff)
downloadcmake-f46b2e914256322fc8d33b425ec01e9d9c1496ba.tar.gz
cmArgumentParser: Model maybe-missing string with wrapper type
Bindings to `std::string` require one value. Some clients have been filtering `keywordsMissingValue` to support keywords that tolerate a missing value. Offer them a type-safe way to achieve this instead.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx38
1 files changed, 14 insertions, 24 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 22ab5f74c8..d2aa63cfaa 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -28,7 +28,6 @@
#include "cm_sys_stat.h"
-#include "cmAlgorithms.h"
#include "cmArgumentParser.h"
#include "cmArgumentParserTypes.h"
#include "cmCMakePath.h"
@@ -3211,7 +3210,8 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
cm::optional<std::string> Content;
bool EscapeQuotes = false;
bool AtOnly = false;
- std::string NewlineStyle;
+ // "NEWLINE_STYLE" requires one value, but we use a custom check below.
+ ArgumentParser::Maybe<std::string> NewlineStyle;
};
static auto const parser =
@@ -3236,15 +3236,10 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
return false;
}
- // Arguments that are allowed to be empty lists. Keep entries sorted!
- static const std::vector<cm::string_view> LIST_ARGS = {
- "NEWLINE_STYLE"_s, // Filter here so we can issue a custom error below.
- };
- auto kwbegin = keywordsMissingValues.cbegin();
- auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS);
- if (kwend != kwbegin) {
- status.SetError(cmStrCat("CONFIGURE keywords missing values:\n ",
- cmJoin(cmMakeRange(kwbegin, kwend), "\n ")));
+ if (!keywordsMissingValues.empty()) {
+ status.SetError(
+ cmStrCat("CONFIGURE keywords missing values:\n ",
+ cmJoin(cmMakeRange(keywordsMissingValues), "\n ")));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3347,7 +3342,10 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
std::string Format;
std::string Compression;
std::string CompressionLevel;
- std::string MTime;
+ // "MTIME" should require one value, but it has long been accidentally
+ // accepted without one and treated as if an empty value were given.
+ // Fixing this would require a policy.
+ ArgumentParser::Maybe<std::string> MTime;
bool Verbose = false;
// "PATHS" requires at least one value, but use a custom check below.
ArgumentParser::MaybeEmpty<std::vector<std::string>> Paths;
@@ -3375,18 +3373,10 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
return false;
}
- // Arguments that are allowed to be empty lists. Keep entries sorted!
- static const std::vector<cm::string_view> LIST_ARGS = {
- "MTIME"_s, // "MTIME" should not be in this list because it requires one
- // value, but it has long been accidentally accepted without
- // one and treated as if an empty value were given.
- // Fixing this would require a policy.
- };
- auto kwbegin = keywordsMissingValues.cbegin();
- auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS);
- if (kwend != kwbegin) {
- status.SetError(cmStrCat("Keywords missing values:\n ",
- cmJoin(cmMakeRange(kwbegin, kwend), "\n ")));
+ if (!keywordsMissingValues.empty()) {
+ status.SetError(
+ cmStrCat("Keywords missing values:\n ",
+ cmJoin(cmMakeRange(keywordsMissingValues), "\n ")));
cmSystemTools::SetFatalErrorOccurred();
return false;
}