mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 07:11:52 +08:00
ArgumentParser: implement HasKeyword helper
This commit is contained in:
@@ -394,6 +394,11 @@ public:
|
|||||||
this->Parse(result, args, unparsedArguments, pos);
|
this->Parse(result, args, unparsedArguments, pos);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasKeyword(cm::string_view key) const
|
||||||
|
{
|
||||||
|
return this->Bindings.Keywords.Find(key) != this->Bindings.Keywords.end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@@ -469,6 +474,11 @@ public:
|
|||||||
return parseResult;
|
return parseResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasKeyword(cm::string_view key) const
|
||||||
|
{
|
||||||
|
return this->Bindings.Keywords.Find(key) != this->Bindings.Keywords.end();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using Base::Instance;
|
using Base::Instance;
|
||||||
using Base::BindKeywordMissingValue;
|
using Base::BindKeywordMissingValue;
|
||||||
|
@@ -300,6 +300,11 @@ bool testArgumentParserDynamic()
|
|||||||
return result.Func4(key, arg);
|
return result.Func4(key, arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cmArgumentParser<void> parserDynamic;
|
||||||
|
parserDynamic.Bind("OPTION_1"_s, result.Option1);
|
||||||
|
ASSERT_TRUE(parserDynamic.HasKeyword("OPTION_1"_s));
|
||||||
|
ASSERT_TRUE(!parserDynamic.HasKeyword("NOT_AN_OPTION"_s));
|
||||||
|
|
||||||
static_cast<ArgumentParser::ParseResult&>(result) =
|
static_cast<ArgumentParser::ParseResult&>(result) =
|
||||||
cmArgumentParser<void>{}
|
cmArgumentParser<void>{}
|
||||||
.Bind(0, result.Pos0)
|
.Bind(0, result.Pos0)
|
||||||
@@ -424,6 +429,9 @@ BIND_TRAILING(parserTrailingDerivedStatic, DerivedTrailingPos);
|
|||||||
|
|
||||||
bool testArgumentParserStatic()
|
bool testArgumentParserStatic()
|
||||||
{
|
{
|
||||||
|
ASSERT_TRUE(parserStatic.HasKeyword("OPTION_1"_s));
|
||||||
|
ASSERT_TRUE(!parserStatic.HasKeyword("NOT_AN_OPTION"_s));
|
||||||
|
|
||||||
std::vector<std::string> unparsedArguments;
|
std::vector<std::string> unparsedArguments;
|
||||||
Result const result = parserStatic.Parse(args, &unparsedArguments);
|
Result const result = parserStatic.Parse(args, &unparsedArguments);
|
||||||
if (!verifyResult(result, unparsedArguments)) {
|
if (!verifyResult(result, unparsedArguments)) {
|
||||||
@@ -438,6 +446,9 @@ bool testArgumentParserStatic()
|
|||||||
|
|
||||||
bool testArgumentParserDerivedStatic()
|
bool testArgumentParserDerivedStatic()
|
||||||
{
|
{
|
||||||
|
ASSERT_TRUE(parserDerivedStatic.HasKeyword("OPTION_1"_s));
|
||||||
|
ASSERT_TRUE(!parserDerivedStatic.HasKeyword("NOT_AN_OPTION"_s));
|
||||||
|
|
||||||
std::vector<std::string> unparsedArguments;
|
std::vector<std::string> unparsedArguments;
|
||||||
Derived const result = parserDerivedStatic.Parse(args, &unparsedArguments);
|
Derived const result = parserDerivedStatic.Parse(args, &unparsedArguments);
|
||||||
if (!verifyResult(result, unparsedArguments)) {
|
if (!verifyResult(result, unparsedArguments)) {
|
||||||
|
Reference in New Issue
Block a user