Skip to content
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
4 changes: 3 additions & 1 deletion include/CLI/impl/Config_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
bool isDefault = false;
if(value.empty() && default_also) {
if(!opt->get_default_str().empty()) {
value = detail::convert_arg_for_ini(opt->get_default_str(), stringQuote, literalQuote, false);
results_t res;
opt->results(res);
value = detail::ini_join(res, arraySeparator, arrayStart, arrayEnd, stringQuote, literalQuote);
} else if(opt->get_expected_min() == 0) {
value = "false";
} else if(opt->get_run_callback_for_default() || !opt->get_required()) {
Expand Down
3 changes: 2 additions & 1 deletion include/CLI/impl/Option_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
}
}

if((allow_extra_args_ || get_expected_max() > 1) && !result.empty() && result.front() == '[' &&
if((allow_extra_args_ || get_expected_max() > 1 || get_type_size() > 1) && !result.empty() &&
result.front() == '[' &&
result.back() == ']') { // this is now a vector string likely from the default or user entry

result.pop_back();
Expand Down
19 changes: 19 additions & 0 deletions tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <tuple>
#include <vector>

#include <array>

TEST_CASE("StringBased: convert_arg_for_ini", "[config]") {

CHECK("\"\"" == CLI::detail::convert_arg_for_ini(std::string{}));
Expand Down Expand Up @@ -4114,3 +4116,20 @@ TEST_CASE_METHOD(TApp, "RoundTripEmptyVector", "[config]") {
app.parse_from_stream(out);
CHECK(cv.empty());
}

TEST_CASE_METHOD(TApp, "RoundTripArrayFloat", "[config]") {
std::array<float, 2> cv{-1.0F, 1.0F};
app.add_option("-c", cv)->capture_default_str();

args = {};

run();
std::string configOut = app.config_to_str(true, true);
app.clear();
std::stringstream out(configOut);
cv[0] = -3.0F;
cv[1] = 4.0F;
app.parse_from_stream(out);
CHECK(cv[0] == -1.0F);
CHECK(cv[1] == 1.0F);
}
Loading