Commit e40645e0849b57976f5066b4e45d65253947e461

Authored by Jarryd Beck
1 parent 76bd60dc

Don't show default when boolean false

Fixes #102. Don't show the default value when it is a boolean and the
value is false. Note that this is a bit of a hack and the
implementation should probably be reevaluated in the future.
include/cxxopts.hpp
... ... @@ -1372,7 +1372,7 @@ namespace cxxopts
1372 1372 {
1373 1373 auto desc = o.desc;
1374 1374  
1375   - if (o.has_default)
  1375 + if (o.has_default && (!o.is_boolean || o.default_value != "false"))
1376 1376 {
1377 1377 desc += toLocalString(" (default: " + o.default_value + ")");
1378 1378 }
... ...
src/example.cpp
... ... @@ -40,6 +40,7 @@ int main(int argc, char* argv[])
40 40 options.add_options()
41 41 ("a,apple", "an apple", cxxopts::value<bool>(apple))
42 42 ("b,bob", "Bob")
  43 + ("t,true", "True", cxxopts::value<bool>()->default_value("true"))
43 44 ("f, file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
44 45 ("i,input", "Input", cxxopts::value<std::string>())
45 46 ("o,output", "Output file", cxxopts::value<std::string>()
... ...