diff options
author | Brad King <brad.king@kitware.com> | 2022-07-26 18:30:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-07-27 11:03:32 (GMT) |
commit | f5d2f6076abe9247ec6a4fc5130267ecc256ab81 (patch) | |
tree | ca4efe9bce5cfceb08445e51c19bf40305759c52 /Source/cmArgumentParser.h | |
parent | 078e2aec8f7a0e6d0be91d0fd565d6c22032f666 (diff) | |
download | CMake-f5d2f6076abe9247ec6a4fc5130267ecc256ab81.zip CMake-f5d2f6076abe9247ec6a4fc5130267ecc256ab81.tar.gz CMake-f5d2f6076abe9247ec6a4fc5130267ecc256ab81.tar.bz2 |
cmArgumentParser: Generalize expected argument count
Replace the boolean expectation with an integer count.
Diffstat (limited to 'Source/cmArgumentParser.h')
-rw-r--r-- | Source/cmArgumentParser.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index a417eb4..d0406e4 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -68,6 +68,16 @@ enum class Continue Yes, }; +struct ExpectAtLeast +{ + std::size_t Count = 0; + + ExpectAtLeast(std::size_t count) + : Count(count) + { + } +}; + class Instance; using KeywordAction = std::function<void(Instance&)>; using KeywordNameAction = std::function<void(Instance&, cm::string_view)>; @@ -93,6 +103,7 @@ public: class Base { public: + using ExpectAtLeast = ArgumentParser::ExpectAtLeast; using Continue = ArgumentParser::Continue; using Instance = ArgumentParser::Instance; using ParseResult = ArgumentParser::ParseResult; @@ -136,7 +147,7 @@ public: { } - void Bind(std::function<Continue(cm::string_view)> f); + void Bind(std::function<Continue(cm::string_view)> f, ExpectAtLeast expect); void Bind(bool& val); void Bind(std::string& val); void Bind(Maybe<std::string>& val); @@ -170,8 +181,9 @@ private: void* Result = nullptr; cm::string_view Keyword; + std::size_t KeywordValuesSeen = 0; + std::size_t KeywordValuesExpected = 0; std::function<Continue(cm::string_view)> KeywordValueFunc; - bool ExpectValue = false; void Consume(cm::string_view arg); void FinishKeyword(); |