diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-08-17 15:03:51 (GMT) |
---|---|---|
committer | Matthew Woehlke <matthew.woehlke@kitware.com> | 2022-08-17 15:03:51 (GMT) |
commit | f2ef60ca547df10eb7e9b3ecf712ad2246d9c008 (patch) | |
tree | ca87c3bf28904355412f154b27ae4385cc4399fd /Source/cmArgumentParser.cxx | |
parent | 5b949bbb9114379120c29134b5effd77e39dd134 (diff) | |
download | CMake-f2ef60ca547df10eb7e9b3ecf712ad2246d9c008.zip CMake-f2ef60ca547df10eb7e9b3ecf712ad2246d9c008.tar.gz CMake-f2ef60ca547df10eb7e9b3ecf712ad2246d9c008.tar.bz2 |
cmArgumentParser: Ignore positional after keyword
Tweak cmArgumentParser to ignore positional arguments once a keyword
argument has been seen. This prevents mingling of keyword arguments
being able to effectively skip positional arguments, with later
arguments being picked up again; this seems highly likely to lead to
user confusion. This is also consistent with how other languages (e.g.
Python) handle a mix of "named" and positional arguments.
Diffstat (limited to 'Source/cmArgumentParser.cxx')
-rw-r--r-- | Source/cmArgumentParser.cxx | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 614d00d..ad57a88 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -139,6 +139,7 @@ void Instance::Consume(std::size_t pos, cm::string_view arg) this->FinishKeyword(); this->Keyword = it->first; this->KeywordValuesSeen = 0; + this->DoneWithPositional = true; if (this->Bindings.ParsedKeyword) { this->Bindings.ParsedKeyword(*this, it->first); } @@ -158,10 +159,12 @@ void Instance::Consume(std::size_t pos, cm::string_view arg) return; } - auto const pit = this->Bindings.Positions.Find(pos); - if (pit != this->Bindings.Positions.end()) { - pit->second(*this, pos, arg); - return; + if (!this->DoneWithPositional) { + auto const pit = this->Bindings.Positions.Find(pos); + if (pit != this->Bindings.Positions.end()) { + pit->second(*this, pos, arg); + return; + } } if (this->UnparsedArguments != nullptr) { |