diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 063d0254..043de209 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -999,8 +999,11 @@ class App { bool config_required = false) { // Remove existing config if present - if(config_ptr_ != nullptr) + if(config_ptr_ != nullptr) { remove_option(config_ptr_); + config_name_ = ""; + config_required_ = false; // Not really needed, but complete + } // Only add config if option passed if(!option_name.empty()) { diff --git a/tests/IniTest.cpp b/tests/IniTest.cpp index 97c57376..d511de9c 100644 --- a/tests/IniTest.cpp +++ b/tests/IniTest.cpp @@ -889,3 +889,24 @@ TEST_F(TApp, DefaultsIniQuotedOutput) { EXPECT_THAT(str, HasSubstr("val1=\"I am a string\"")); EXPECT_THAT(str, HasSubstr("val2='I am a \"confusing\" string'")); } + +// #298 +TEST_F(TApp, StopReadingConfigOnClear) { + + TempFile tmpini{"TestIniTmp.ini"}; + + app.set_config("--config", tmpini); + app.set_config(); // Should *not* read config file + + { + std::ofstream out{tmpini}; + out << "volume=1" << std::endl; + } + + int volume = 0; + app.add_option("--volume", volume, "volume1"); + + run(); + + EXPECT_EQ(volume, 0); +}