Commit 32afbc65263e42fa089f473d5a6131983d9b7200
1 parent
e9d20c2c
Fix default bool values
Fixes #382. Keep boolean values when parsing into a reference.
Showing
2 changed files
with
7 additions
and
2 deletions
include/cxxopts.hpp
| ... | ... | @@ -1246,7 +1246,8 @@ class standard_value<bool> : public abstract_value<bool> |
| 1246 | 1246 | explicit standard_value(bool* b) |
| 1247 | 1247 | : abstract_value(b) |
| 1248 | 1248 | { |
| 1249 | - set_default_and_implicit(); | |
| 1249 | + m_implicit = true; | |
| 1250 | + m_implicit_value = "true"; | |
| 1250 | 1251 | } |
| 1251 | 1252 | |
| 1252 | 1253 | std::shared_ptr<Value> | ... | ... |
test/options.cpp
| ... | ... | @@ -406,10 +406,12 @@ TEST_CASE("Default values", "[default]") |
| 406 | 406 | TEST_CASE("Parse into a reference", "[reference]") |
| 407 | 407 | { |
| 408 | 408 | int value = 0; |
| 409 | + bool b_value = true; | |
| 409 | 410 | |
| 410 | 411 | cxxopts::Options options("into_reference", "parses into a reference"); |
| 411 | 412 | options.add_options() |
| 412 | - ("ref", "A reference", cxxopts::value(value)); | |
| 413 | + ("ref", "A reference", cxxopts::value(value)) | |
| 414 | + ("bool", "A bool", cxxopts::value(b_value)); | |
| 413 | 415 | |
| 414 | 416 | Argv av({"into_reference", "--ref", "42"}); |
| 415 | 417 | |
| ... | ... | @@ -419,6 +421,8 @@ TEST_CASE("Parse into a reference", "[reference]") |
| 419 | 421 | auto result = options.parse(argc, argv); |
| 420 | 422 | CHECK(result.count("ref") == 1); |
| 421 | 423 | CHECK(value == 42); |
| 424 | + CHECK(result.count("bool") == 0); | |
| 425 | + CHECK(b_value == true); | |
| 422 | 426 | } |
| 423 | 427 | |
| 424 | 428 | TEST_CASE("Integers", "[options]") | ... | ... |