1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

Fix #298, resetting config option (#301)

This commit is contained in:
Henry Schreiner 2019-07-25 16:16:11 -04:00 committed by GitHub
parent 821940c368
commit f583e5baf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -999,8 +999,11 @@ class App {
bool config_required = false) { bool config_required = false) {
// Remove existing config if present // Remove existing config if present
if(config_ptr_ != nullptr) if(config_ptr_ != nullptr) {
remove_option(config_ptr_); remove_option(config_ptr_);
config_name_ = "";
config_required_ = false; // Not really needed, but complete
}
// Only add config if option passed // Only add config if option passed
if(!option_name.empty()) { if(!option_name.empty()) {

View File

@ -889,3 +889,24 @@ TEST_F(TApp, DefaultsIniQuotedOutput) {
EXPECT_THAT(str, HasSubstr("val1=\"I am a string\"")); EXPECT_THAT(str, HasSubstr("val1=\"I am a string\""));
EXPECT_THAT(str, HasSubstr("val2='I am a \"confusing\" 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);
}