From b1f0cb806c6b6ddd38264c830e2236a103e46d34 Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Fri, 27 Oct 2017 12:04:51 +1100 Subject: [PATCH] fix default --- CHANGELOG.md | 2 ++ include/cxxopts.hpp | 11 ++++------- test/options.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4a6291..eea975d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ options. The project adheres to semantic versioning. * `Options::parse` returns a ParseResult rather than storing the parse result internally. +* Options with default values now get counted as appearing once if they + were not specified by the user. ### Added diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 553ed4b..dc8ffde 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -887,12 +887,6 @@ namespace cxxopts m_value->parse(); } - int - count() const - { - return m_count; - } - const Value& value() const { return *m_value; } @@ -961,6 +955,7 @@ namespace cxxopts { ensure_value(details); m_value->parse(); + m_count++; } size_t @@ -1645,7 +1640,9 @@ ParseResult::parse(int& argc, char**& argv) auto& detail = opt.second; auto& value = detail->value(); - if(!detail->count() && value.has_default()){ + auto& store = m_results[detail]; + + if(!store.count() && value.has_default()){ parse_default(detail); } } diff --git a/test/options.cpp b/test/options.cpp index cc06389..ed39a10 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -238,7 +238,7 @@ TEST_CASE("Default values", "[default]") } SECTION("When values provided") { - Argv av({"implicit", "default", "5"}); + Argv av({"implicit", "--default", "5"}); char** argv = av.argv(); auto argc = av.argc(); -- libgit2 0.21.4