From 142a5241eaa4ba041ea81edd68d6a40a68e2b293 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Jul 2017 23:46:08 +0100 Subject: Provide way of overriding a default value with an empty string --- icetray/icetray/options.cpp | 9 ++++++++- icetray/unittests/testIceTrayOptions.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/icetray/icetray/options.cpp b/icetray/icetray/options.cpp index a12a7d0..dcc6bb0 100644 --- a/icetray/icetray/options.cpp +++ b/icetray/icetray/options.cpp @@ -46,7 +46,14 @@ namespace IceTray { for (const auto & optDesc : all.options()) { po::option opt; opt.value = p->getPropertyAsList(optDesc->long_name()); - if (opt.value.empty()) continue; + if (opt.value.empty()) { + // If it was processed as an empty list and was empty, it wasn't there. + if (p->getProperty(optDesc->long_name()).empty()) { + continue; + } + // If it was process as an empty list but wasn't empty, treat as the empty string. + opt.value = { "" }; + } opt.string_key = optDesc->long_name(); opt.unregistered = false; result.options.push_back(opt); diff --git a/icetray/unittests/testIceTrayOptions.cpp b/icetray/unittests/testIceTrayOptions.cpp index 3eb08fc..62f921a 100644 --- a/icetray/unittests/testIceTrayOptions.cpp +++ b/icetray/unittests/testIceTrayOptions.cpp @@ -30,3 +30,17 @@ BOOST_AUTO_TEST_CASE( testOptions ) BOOST_REQUIRE_EQUAL(8, myOpts->testVec[3]); } +BOOST_AUTO_TEST_CASE( overrideDefaultWithQuotesString ) +{ + DI di({ R"C(--testString="some \"Quotes\" string")C" }); + IceTray::OptionsResolver myOpts; + BOOST_REQUIRE_EQUAL("some \"Quotes\" string", myOpts->testString); +} + +BOOST_AUTO_TEST_CASE( overrideDefaultWithEmptyString ) +{ + DI di({ R"C(--testString="")C" }); + IceTray::OptionsResolver myOpts; + BOOST_REQUIRE(myOpts->testString.empty()); +} + -- cgit v1.2.3