diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index f53cf7ac..c1592b82 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -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()) { diff --git a/include/CLI/impl/Option_inl.hpp b/include/CLI/impl/Option_inl.hpp index 61d7ddd4..62a8becc 100644 --- a/include/CLI/impl/Option_inl.hpp +++ b/include/CLI/impl/Option_inl.hpp @@ -686,7 +686,8 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector 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(); diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp index 23f40e6c..f47ca557 100644 --- a/tests/ConfigFileTest.cpp +++ b/tests/ConfigFileTest.cpp @@ -14,6 +14,8 @@ #include #include +#include + TEST_CASE("StringBased: convert_arg_for_ini", "[config]") { CHECK("\"\"" == CLI::detail::convert_arg_for_ini(std::string{})); @@ -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 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); +}