summaryrefslogtreecommitdiffstats
path: root/Source/cmArgumentParser.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-28 19:49:48 (GMT)
committerBrad King <brad.king@kitware.com>2022-07-28 12:24:47 (GMT)
commit7ca8d9f0f854acd71f2a2134d86a1e182496c4cc (patch)
treed8d483043a1c825b2f560d723c8f1bb9274ca688 /Source/cmArgumentParser.cxx
parent110baa254bc2e5589e073affb8ea445e825d20eb (diff)
downloadCMake-7ca8d9f0f854acd71f2a2134d86a1e182496c4cc.zip
CMake-7ca8d9f0f854acd71f2a2134d86a1e182496c4cc.tar.gz
CMake-7ca8d9f0f854acd71f2a2134d86a1e182496c4cc.tar.bz2
cmArgumentParser: Model non-empty strings with wrapper type
Some clients have been explicitly checking whether the string specified after a keyword is empty. Offer them a way to specify that the string must be non-empty as part of the binding type.
Diffstat (limited to 'Source/cmArgumentParser.cxx')
-rw-r--r--Source/cmArgumentParser.cxx14
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx
index 05f8ce8..614d00d 100644
--- a/Source/cmArgumentParser.cxx
+++ b/Source/cmArgumentParser.cxx
@@ -76,6 +76,20 @@ void Instance::Bind(std::string& val)
ExpectAtLeast{ 1 });
}
+void Instance::Bind(NonEmpty<std::string>& val)
+{
+ this->Bind(
+ [this, &val](cm::string_view arg) -> Continue {
+ if (arg.empty() && this->ParseResults) {
+ this->ParseResults->AddKeywordError(this->Keyword,
+ " empty string not allowed\n");
+ }
+ val.assign(std::string(arg));
+ return Continue::No;
+ },
+ ExpectAtLeast{ 1 });
+}
+
void Instance::Bind(Maybe<std::string>& val)
{
this->Bind(