Skip to content

Commit

Permalink
Bug fixes in latest release (#1005)
Browse files Browse the repository at this point in the history
Fix an issue with environmental variable parsing in option_groups, and
an issue with remaining in config files.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
phlptp and pre-commit-ci[bot] committed Feb 10, 2024
1 parent f4d0731 commit d98a387
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
15 changes: 7 additions & 8 deletions include/CLI/impl/App_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,9 @@ CLI11_INLINE void App::_process_env() {
}

for(App_p &sub : subcommands_) {
if(sub->get_name().empty() || !sub->parse_complete_callback_) {
if(sub->count_all() > 0) {
// only process environment variables if the callback has actually been triggered already
sub->_process_env();
}
if(sub->get_name().empty() || (sub->count_all() > 0 && !sub->parse_complete_callback_)) {
// only process environment variables if the callback has actually been triggered already
sub->_process_env();
}
}
}
Expand Down Expand Up @@ -1482,11 +1480,12 @@ CLI11_INLINE bool App::_parse_single_config(const ConfigItem &item, std::size_t

if(op == nullptr) {
// If the option was not present
if(get_allow_config_extras() == config_extras_mode::capture)
if(get_allow_config_extras() == config_extras_mode::capture) {
// Should we worry about classifying the extras properly?
missing_.emplace_back(detail::Classifier::NONE, item.fullname());
for(const auto &input : item.inputs) {
missing_.emplace_back(detail::Classifier::NONE, input);
for(const auto &input : item.inputs) {
missing_.emplace_back(detail::Classifier::NONE, input);
}
}
return false;
}
Expand Down
21 changes: 20 additions & 1 deletion tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,26 @@ TEST_CASE_METHOD(TApp, "IniGetRemainingOption", "[config]") {
int two{0};
app.add_option("--two", two);
REQUIRE_NOTHROW(run());
std::vector<std::string> ExpectedRemaining = {ExtraOption, "3"};
std::vector<std::string> ExpectedRemaining = {ExtraOption, ExtraOptionValue};
CHECK(ExpectedRemaining == app.remaining());
}

TEST_CASE_METHOD(TApp, "IniIgnoreRemainingOption", "[config]") {
TempFile tmpini{"TestIniTmp.ini"};

app.set_config("--config", tmpini);
app.allow_config_extras(CLI::config_extras_mode::ignore);

{
std::ofstream out{tmpini};
out << "three=3\n";
out << "two=99\n";
}

int two{0};
app.add_option("--two", two);
REQUIRE_NOTHROW(run());
std::vector<std::string> ExpectedRemaining = {};
CHECK(ExpectedRemaining == app.remaining());
}

Expand Down

0 comments on commit d98a387

Please sign in to comment.