Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #298, resetting config option #301

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 21 additions & 0 deletions tests/IniTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}