From 9a13d34825b36b9f06f221214258a83675e65a24 Mon Sep 17 00:00:00 2001 From: Jesus Gonzalez Date: Mon, 15 Jan 2018 20:30:48 +0100 Subject: [PATCH] Add default "default" value of "false" to boolean options, therefore allowing to call result["boolOpt"].as() without throwing an exception. --- include/cxxopts.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 6a6a85f..aa44a01 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -855,13 +855,13 @@ namespace cxxopts standard_value() { - set_implicit(); + set_default_and_implicit(); } standard_value(bool* b) : abstract_value(b) { - set_implicit(); + set_default_and_implicit(); } std::shared_ptr @@ -873,8 +873,10 @@ namespace cxxopts private: void - set_implicit() + set_default_and_implicit() { + m_default = true; + m_default_value = "false"; m_implicit = true; m_implicit_value = "true"; }