Throw exception in case of unknown argument

This commit is contained in:
Stephan van Veen 2019-05-18 14:22:10 +02:00
parent 36bdfe4a55
commit 9e7b80034e
2 changed files with 5 additions and 2 deletions

View File

@ -462,10 +462,13 @@ class ArgumentParser {
auto tArgument = tIterator->second; auto tArgument = tIterator->second;
it = tArgument->consume(it, end, tCurrentArgument); it = tArgument->consume(it, end, tCurrentArgument);
} }
else {
throw std::runtime_error("Unknown argument");
}
} }
} }
else { else {
++it; throw std::runtime_error("Unknown argument");
} }
} }
} }

View File

@ -34,5 +34,5 @@ TEST_CASE("Parse unknown optional argument", "[compound_arguments]") {
.action([](const std::string& val) { return std::stoull(val); }) .action([](const std::string& val) { return std::stoull(val); })
.help("memory in MB to give the VMM when loading"); .help("memory in MB to give the VMM when loading");
bfm.parse_args({ "./test.exe", "-om" }); REQUIRE_THROWS(bfm.parse_args({ "./test.exe", "-om" }));
} }