From 9a7efb681331f77a3873bd9fb5694ad46338c0f7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 20 Jul 2022 15:44:44 -0400 Subject: 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. --- Source/cmArgumentParser.cxx | 3 +++ Source/cmArgumentParser.h | 11 +++++++++++ Source/cmParseArgumentsCommand.cxx | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) 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; +using KeywordNameAction = std::function; // using KeywordActionMap = cm::flat_map; class KeywordActionMap @@ -79,6 +80,7 @@ class ActionMap { public: KeywordActionMap Keywords; + KeywordNameAction KeywordMissingValue; }; class Base @@ -100,6 +102,12 @@ public: assert(inserted); static_cast(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 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; struct UserArgumentParser : public cmArgumentParser { + void BindKeywordsMissingValue(std::vector& ref) + { + this->cmArgumentParser::BindKeywordMissingValue( + [&ref](Instance&, cm::string_view arg) { ref.emplace_back(arg); }); + } + template void Bind(std::vector const& names, std::map& ref, H duplicateKey) @@ -211,8 +217,9 @@ bool cmParseArgumentsCommand(std::vector const& args, } std::vector keywordsMissingValues; + parser.BindKeywordsMissingValue(keywordsMissingValues); - parser.Parse(list, &unparsed, &keywordsMissingValues); + parser.Parse(list, &unparsed); PassParsedArguments( prefix, status.GetMakefile(), options, singleValArgs, multiValArgs, -- cgit v0.12