Add ParseResult::contains method (#440)

This commit is contained in:
levonwaveye
2024-10-23 13:14:32 -07:00
committed by GitHub
parent 63d1b65a69
commit 10a7a64779
2 changed files with 9 additions and 0 deletions

View File

@@ -1743,6 +1743,12 @@ CXXOPTS_DIAGNOSTIC_POP
return viter->second.count();
}
bool
contains(const std::string& o) const
{
return static_cast<bool>(count(o));
}
const OptionValue&
operator[](const std::string& option) const
{

View File

@@ -89,6 +89,7 @@ TEST_CASE("Basic options", "[options]")
auto result = options.parse(argc, actual_argv);
CHECK(result.count("long") == 1);
CHECK(result.contains("long"));
CHECK(result.count("s") == 1);
CHECK(result.count("value") == 1);
CHECK(result.count("a") == 1);
@@ -112,6 +113,8 @@ TEST_CASE("Basic options", "[options]")
CHECK(arguments[2].key() == "value");
CHECK(arguments[3].key() == "av");
CHECK(result.count("nothing") == 0);
CHECK_FALSE(result.contains("nothing"));
CHECK_THROWS_AS(result["nothing"].as<std::string>(), cxxopts::exceptions::option_has_no_value);
CHECK(options.program() == "tester");