Fix default bool values
Fixes #382. Keep boolean values when parsing into a reference.
This commit is contained in:
parent
e9d20c2c07
commit
32afbc6526
@ -1246,7 +1246,8 @@ class standard_value<bool> : public abstract_value<bool>
|
|||||||
explicit standard_value(bool* b)
|
explicit standard_value(bool* b)
|
||||||
: abstract_value(b)
|
: abstract_value(b)
|
||||||
{
|
{
|
||||||
set_default_and_implicit();
|
m_implicit = true;
|
||||||
|
m_implicit_value = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Value>
|
std::shared_ptr<Value>
|
||||||
|
@ -406,10 +406,12 @@ TEST_CASE("Default values", "[default]")
|
|||||||
TEST_CASE("Parse into a reference", "[reference]")
|
TEST_CASE("Parse into a reference", "[reference]")
|
||||||
{
|
{
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
bool b_value = true;
|
||||||
|
|
||||||
cxxopts::Options options("into_reference", "parses into a reference");
|
cxxopts::Options options("into_reference", "parses into a reference");
|
||||||
options.add_options()
|
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"});
|
Argv av({"into_reference", "--ref", "42"});
|
||||||
|
|
||||||
@ -419,6 +421,8 @@ TEST_CASE("Parse into a reference", "[reference]")
|
|||||||
auto result = options.parse(argc, argv);
|
auto result = options.parse(argc, argv);
|
||||||
CHECK(result.count("ref") == 1);
|
CHECK(result.count("ref") == 1);
|
||||||
CHECK(value == 42);
|
CHECK(value == 42);
|
||||||
|
CHECK(result.count("bool") == 0);
|
||||||
|
CHECK(b_value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Integers", "[options]")
|
TEST_CASE("Integers", "[options]")
|
||||||
|
Loading…
Reference in New Issue
Block a user