diff options
author | Brad King <brad.king@kitware.com> | 2022-06-28 19:49:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-28 12:24:47 (GMT) |
commit | 7ca8d9f0f854acd71f2a2134d86a1e182496c4cc (patch) | |
tree | d8d483043a1c825b2f560d723c8f1bb9274ca688 /Source/cmArgumentParser.cxx | |
parent | 110baa254bc2e5589e073affb8ea445e825d20eb (diff) | |
download | CMake-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.cxx | 14 |
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( |