From b34db1db69150b4a35b8c3a692b16ebf70cda89c Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 29 Dec 2020 14:02:08 -0500 Subject: cmCommandLineArgument supports ZeroOrOne arguments This allows us to parse command line arguments such as `-j` || `-j2` --- Source/cmCommandLineArgument.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/cmCommandLineArgument.h b/Source/cmCommandLineArgument.h index aa96305..16564dd 100644 --- a/Source/cmCommandLineArgument.h +++ b/Source/cmCommandLineArgument.h @@ -13,6 +13,7 @@ struct cmCommandLineArgument Zero, One, Two, + ZeroOrOne, }; std::string InvalidSyntaxMessage; @@ -72,11 +73,18 @@ struct cmCommandLineArgument parseState = ParseMode::SyntaxError; } - } else if (this->Type == Values::One) { + } else if (this->Type == Values::One || this->Type == Values::ZeroOrOne) { if (input.size() == this->Name.size()) { ++index; if (index >= allArgs.size() || allArgs[index][0] == '-') { - parseState = ParseMode::ValueError; + if (this->Type == Values::ZeroOrOne) { + parseState = + this->StoreCall(std::string{}, std::forward(state)...) + ? ParseMode::Valid + : ParseMode::Invalid; + } else { + parseState = ParseMode::ValueError; + } } else { parseState = this->StoreCall(allArgs[index], std::forward(state)...) -- cgit v0.12