1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-02 13:43:52 +00:00

fix: parse config file remaining (#839)

* update the storage of remaining argument for config files, so that they work through the `remaining_for_passthrough` with values when parsed a second time.

* style: pre-commit.ci fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top 2023-02-11 05:42:46 -08:00 committed by GitHub
parent d335ca1172
commit 69c79b0343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -87,6 +87,10 @@ app.allow_config_extras(CLI::config_extras_mode::ignore_all);
will completely ignore any mismatches, extras, or other issues with the config
file
Config file extras are stored in the remaining output as two components. The
first is the name of the field including subcommands using dot notation the
second (or more) are the argument fields.
### Getting the used configuration file name
If it is needed to get the configuration file name used this can be obtained via

View File

@ -1414,6 +1414,9 @@ CLI11_INLINE bool App::_parse_single_config(const ConfigItem &item, std::size_t
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);
}
return false;
}

View File

@ -509,10 +509,47 @@ TEST_CASE_METHOD(TApp, "IniGetRemainingOption", "[config]") {
int two{0};
app.add_option("--two", two);
REQUIRE_NOTHROW(run());
std::vector<std::string> ExpectedRemaining = {ExtraOption};
std::vector<std::string> ExpectedRemaining = {ExtraOption, "3"};
CHECK(ExpectedRemaining == app.remaining());
}
TEST_CASE_METHOD(TApp, "IniRemainingSub", "[config]") {
TempFile tmpini{"TestIniTmp.ini"};
app.set_config("--config", tmpini);
auto *map = app.add_subcommand("map");
map->allow_config_extras();
{
std::ofstream out{tmpini};
out << "[map]\n";
out << "a = 1\n";
out << "b=[1,2,3]\n";
out << "c = 3" << std::endl;
}
REQUIRE_NOTHROW(run());
std::vector<std::string> rem = map->remaining();
REQUIRE(rem.size() == 8U);
CHECK(rem[0] == "map.a");
CHECK(rem[2] == "map.b");
CHECK(rem[6] == "map.c");
CHECK(rem[5] == "3");
int a{0};
int c{0};
std::vector<int> b;
map->add_option("-a", a);
map->add_option("-b", b);
map->add_option("-c", c);
CHECK_NOTHROW(app.parse(app.remaining_for_passthrough()));
CHECK(a == 1);
CHECK(c == 3);
REQUIRE(b.size() == 3U);
CHECK(b[1] == 2);
}
TEST_CASE_METHOD(TApp, "IniGetNoRemaining", "[config]") {
TempFile tmpini{"TestIniTmp.ini"};