diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-12-29 19:02:08 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-01-06 14:11:18 (GMT) |
commit | b34db1db69150b4a35b8c3a692b16ebf70cda89c (patch) | |
tree | 422700ea611c3c57aa34445409deb0114aa9261b /Source/cmCommandLineArgument.h | |
parent | 0fb78576b00aa9ca39112210d19ec53b0e6e975c (diff) | |
download | CMake-b34db1db69150b4a35b8c3a692b16ebf70cda89c.zip CMake-b34db1db69150b4a35b8c3a692b16ebf70cda89c.tar.gz CMake-b34db1db69150b4a35b8c3a692b16ebf70cda89c.tar.bz2 |
cmCommandLineArgument supports ZeroOrOne arguments
This allows us to parse command line arguments such as `-j` || `-j2`
Diffstat (limited to 'Source/cmCommandLineArgument.h')
-rw-r--r-- | Source/cmCommandLineArgument.h | 12 |
1 files 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<CallState>(state)...) + ? ParseMode::Valid + : ParseMode::Invalid; + } else { + parseState = ParseMode::ValueError; + } } else { parseState = this->StoreCall(allArgs[index], std::forward<CallState>(state)...) |