Fix default bool values

Fixes #382. Keep boolean values when parsing into a reference.
This commit is contained in:
Jarryd Beck 2022-12-15 07:08:03 +11:00
parent e9d20c2c07
commit 32afbc6526
2 changed files with 7 additions and 2 deletions

View File

@ -1246,7 +1246,8 @@ class standard_value<bool> : public abstract_value<bool>
explicit standard_value(bool* b)
: abstract_value(b)
{
set_default_and_implicit();
m_implicit = true;
m_implicit_value = "true";
}
std::shared_ptr<Value>

View File

@ -406,10 +406,12 @@ TEST_CASE("Default values", "[default]")
TEST_CASE("Parse into a reference", "[reference]")
{
int value = 0;
bool b_value = true;
cxxopts::Options options("into_reference", "parses into a reference");
options.add_options()
("ref", "A reference", cxxopts::value(value));
("ref", "A reference", cxxopts::value(value))
("bool", "A bool", cxxopts::value(b_value));
Argv av({"into_reference", "--ref", "42"});
@ -419,6 +421,8 @@ TEST_CASE("Parse into a reference", "[reference]")
auto result = options.parse(argc, argv);
CHECK(result.count("ref") == 1);
CHECK(value == 42);
CHECK(result.count("bool") == 0);
CHECK(b_value == true);
}
TEST_CASE("Integers", "[options]")