diff options
author | Brad King <brad.king@kitware.com> | 2022-07-20 19:44:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-25 17:48:26 (GMT) |
commit | 9a7efb681331f77a3873bd9fb5694ad46338c0f7 (patch) | |
tree | 87fa13089003ae4a54252e5e42cbac4b14721fe2 /Source | |
parent | a0ff592bf4744546159ae585d7c7727d49e2d138 (diff) | |
download | CMake-9a7efb681331f77a3873bd9fb5694ad46338c0f7.zip CMake-9a7efb681331f77a3873bd9fb5694ad46338c0f7.tar.gz CMake-9a7efb681331f77a3873bd9fb5694ad46338c0f7.tar.bz2 |
cmArgumentParser: Offer private binding to cmParseArgumentsCommand
The `keywordsMissingValue` argument to `Parse()` is now needed only for
the `cmake_parse_arguments` result `_KEYWORDS_MISSING_VALUES`. Offer
its implementation a private binding for this. Our internal clients can
use `ArgumentParser::NonEmpty<>` and friends to enforce the presence of
values.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmArgumentParser.cxx | 3 | ||||
-rw-r--r-- | Source/cmArgumentParser.h | 11 | ||||
-rw-r--r-- | Source/cmParseArgumentsCommand.cxx | 9 |
3 files changed, 22 insertions, 1 deletions
diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 25d5c68..fcced96 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -116,6 +116,9 @@ void Instance::FinishKeyword() if (this->KeywordsMissingValue != nullptr) { this->KeywordsMissingValue->emplace_back(this->Keyword); } + if (this->Bindings.KeywordMissingValue) { + this->Bindings.KeywordMissingValue(*this, this->Keyword); + } } } diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index 8fda8b7..ae3a000 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -64,6 +64,7 @@ AsParseResultPtr(Result&) class Instance; using KeywordAction = std::function<void(Instance&)>; +using KeywordNameAction = std::function<void(Instance&, cm::string_view)>; // using KeywordActionMap = cm::flat_map<cm::string_view, KeywordAction>; class KeywordActionMap @@ -79,6 +80,7 @@ class ActionMap { public: KeywordActionMap Keywords; + KeywordNameAction KeywordMissingValue; }; class Base @@ -100,6 +102,12 @@ public: assert(inserted); static_cast<void>(inserted); } + + void BindKeywordMissingValue(KeywordNameAction action) + { + assert(!this->Bindings.KeywordMissingValue); + this->Bindings.KeywordMissingValue = std::move(action); + } }; class Instance @@ -233,6 +241,9 @@ public: } protected: + using Base::Instance; + using Base::BindKeywordMissingValue; + template <typename T> bool Bind(cm::string_view name, T& ref) { diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index 31538b6..7e19566 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -48,6 +48,12 @@ using options_set = std::set<cm::string_view>; struct UserArgumentParser : public cmArgumentParser<void> { + void BindKeywordsMissingValue(std::vector<cm::string_view>& ref) + { + this->cmArgumentParser<void>::BindKeywordMissingValue( + [&ref](Instance&, cm::string_view arg) { ref.emplace_back(arg); }); + } + template <typename T, typename H> void Bind(std::vector<std::string> const& names, std::map<std::string, T>& ref, H duplicateKey) @@ -211,8 +217,9 @@ bool cmParseArgumentsCommand(std::vector<std::string> const& args, } std::vector<cm::string_view> keywordsMissingValues; + parser.BindKeywordsMissingValue(keywordsMissingValues); - parser.Parse(list, &unparsed, &keywordsMissingValues); + parser.Parse(list, &unparsed); PassParsedArguments( prefix, status.GetMakefile(), options, singleValArgs, multiValArgs, |