Commit e792760ab91b30028f49df4edd72687d4f0e684c

Authored by Jarryd Beck
1 parent 76717cb3

Changes default values so that they aren't counted

Fixes #96. Default values of options not specified on the command line
had a `count` of 1. It would be better if they had a count of 0 because
they were not actually specified, so that count is only for options
given by the user.
include/cxxopts.hpp
@@ -1003,7 +1003,6 @@ namespace cxxopts @@ -1003,7 +1003,6 @@ namespace cxxopts
1003 { 1003 {
1004 ensure_value(details); 1004 ensure_value(details);
1005 m_value->parse(); 1005 m_value->parse();
1006 - m_count++;  
1007 } 1006 }
1008 1007
1009 size_t 1008 size_t
test/options.cpp
@@ -243,7 +243,7 @@ TEST_CASE("Default values", "[default]") @@ -243,7 +243,7 @@ TEST_CASE("Default values", "[default]")
243 auto argc = av.argc(); 243 auto argc = av.argc();
244 244
245 auto result = options.parse(argc, argv); 245 auto result = options.parse(argc, argv);
246 - CHECK(result.count("default") == 1); 246 + CHECK(result.count("default") == 0);
247 CHECK(result["default"].as<int>() == 42); 247 CHECK(result["default"].as<int>() == 42);
248 } 248 }
249 249
@@ -441,9 +441,9 @@ TEST_CASE(&quot;Booleans&quot;, &quot;[boolean]&quot;) { @@ -441,9 +441,9 @@ TEST_CASE(&quot;Booleans&quot;, &quot;[boolean]&quot;) {
441 REQUIRE(result.count("bool") == 1); 441 REQUIRE(result.count("bool") == 1);
442 REQUIRE(result.count("debug") == 1); 442 REQUIRE(result.count("debug") == 1);
443 REQUIRE(result.count("timing") == 1); 443 REQUIRE(result.count("timing") == 1);
444 - REQUIRE(result.count("noExplicitDefault") == 1);  
445 - REQUIRE(result.count("defaultTrue") == 1);  
446 - REQUIRE(result.count("defaultFalse") == 1); 444 + REQUIRE(result.count("noExplicitDefault") == 0);
  445 + REQUIRE(result.count("defaultTrue") == 0);
  446 + REQUIRE(result.count("defaultFalse") == 0);
447 447
448 CHECK(result["bool"].as<bool>() == false); 448 CHECK(result["bool"].as<bool>() == false);
449 CHECK(result["debug"].as<bool>() == true); 449 CHECK(result["debug"].as<bool>() == true);