fix default

This commit is contained in:
Jarryd Beck 2017-10-27 12:04:51 +11:00
parent 65beaeb2e9
commit b1f0cb806c
3 changed files with 7 additions and 8 deletions

View File

@ -9,6 +9,8 @@ options. The project adheres to semantic versioning.
* `Options::parse` returns a ParseResult rather than storing the parse * `Options::parse` returns a ParseResult rather than storing the parse
result internally. result internally.
* Options with default values now get counted as appearing once if they
were not specified by the user.
### Added ### Added

View File

@ -887,12 +887,6 @@ namespace cxxopts
m_value->parse(); m_value->parse();
} }
int
count() const
{
return m_count;
}
const Value& value() const { const Value& value() const {
return *m_value; return *m_value;
} }
@ -961,6 +955,7 @@ namespace cxxopts
{ {
ensure_value(details); ensure_value(details);
m_value->parse(); m_value->parse();
m_count++;
} }
size_t size_t
@ -1645,7 +1640,9 @@ ParseResult::parse(int& argc, char**& argv)
auto& detail = opt.second; auto& detail = opt.second;
auto& value = detail->value(); auto& value = detail->value();
if(!detail->count() && value.has_default()){ auto& store = m_results[detail];
if(!store.count() && value.has_default()){
parse_default(detail); parse_default(detail);
} }
} }

View File

@ -238,7 +238,7 @@ TEST_CASE("Default values", "[default]")
} }
SECTION("When values provided") { SECTION("When values provided") {
Argv av({"implicit", "default", "5"}); Argv av({"implicit", "--default", "5"});
char** argv = av.argv(); char** argv = av.argv();
auto argc = av.argc(); auto argc = av.argc();