Commit b1f0cb806c6b6ddd38264c830e2236a103e46d34
1 parent
65beaeb2
fix default
Showing
3 changed files
with
7 additions
and
8 deletions
CHANGELOG.md
| ... | ... | @@ -9,6 +9,8 @@ options. The project adheres to semantic versioning. |
| 9 | 9 | |
| 10 | 10 | * `Options::parse` returns a ParseResult rather than storing the parse |
| 11 | 11 | result internally. |
| 12 | +* Options with default values now get counted as appearing once if they | |
| 13 | + were not specified by the user. | |
| 12 | 14 | |
| 13 | 15 | ### Added |
| 14 | 16 | ... | ... |
include/cxxopts.hpp
| ... | ... | @@ -887,12 +887,6 @@ namespace cxxopts |
| 887 | 887 | m_value->parse(); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | - int | |
| 891 | - count() const | |
| 892 | - { | |
| 893 | - return m_count; | |
| 894 | - } | |
| 895 | - | |
| 896 | 890 | const Value& value() const { |
| 897 | 891 | return *m_value; |
| 898 | 892 | } |
| ... | ... | @@ -961,6 +955,7 @@ namespace cxxopts |
| 961 | 955 | { |
| 962 | 956 | ensure_value(details); |
| 963 | 957 | m_value->parse(); |
| 958 | + m_count++; | |
| 964 | 959 | } |
| 965 | 960 | |
| 966 | 961 | size_t |
| ... | ... | @@ -1645,7 +1640,9 @@ ParseResult::parse(int& argc, char**& argv) |
| 1645 | 1640 | auto& detail = opt.second; |
| 1646 | 1641 | auto& value = detail->value(); |
| 1647 | 1642 | |
| 1648 | - if(!detail->count() && value.has_default()){ | |
| 1643 | + auto& store = m_results[detail]; | |
| 1644 | + | |
| 1645 | + if(!store.count() && value.has_default()){ | |
| 1649 | 1646 | parse_default(detail); |
| 1650 | 1647 | } |
| 1651 | 1648 | } | ... | ... |
test/options.cpp
| ... | ... | @@ -238,7 +238,7 @@ TEST_CASE("Default values", "[default]") |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | SECTION("When values provided") { |
| 241 | - Argv av({"implicit", "default", "5"}); | |
| 241 | + Argv av({"implicit", "--default", "5"}); | |
| 242 | 242 | |
| 243 | 243 | char** argv = av.argv(); |
| 244 | 244 | auto argc = av.argc(); | ... | ... |