Fixes #245: Mention the option name when throwing on "no value" (#246)

* Fixes #245:

* Added a new exception type: `option_has_no_value_exception`; throwing it when an option has no value we can cast with `as()`, instead of an `std::domain_error`.
* The `OptionValue` type now holds a pointer to the long option name (in its corresponding key within ParseResults's `m_results` field.
This commit is contained in:
Eyal Rozenberg
2020-07-23 17:27:04 +10:00
committed by GitHub
parent 1b660d5680
commit 5f43f4cbfe
2 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ TEST_CASE("Basic options", "[options]")
CHECK(arguments[2].key() == "value");
CHECK(arguments[3].key() == "av");
CHECK_THROWS_AS(result["nothing"].as<std::string>(), std::domain_error&);
CHECK_THROWS_AS(result["nothing"].as<std::string>(), cxxopts::option_has_no_value_exception&);
}
TEST_CASE("Short options", "[options]")