mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user