Skip to content

Commit 79f9557

Browse files
authored
Merge branch 'main' into footer_header_formatting_disable
2 parents 7218ee5 + c31476b commit 79f9557

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
- id: debug-statements
2727

2828
- repo: https://github.com/pre-commit/mirrors-clang-format
29-
rev: v20.1.0
29+
rev: v20.1.3
3030
hooks:
3131
- id: clang-format
3232
types_or: [c++, c, cuda]

include/CLI/App.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ class App {
733733
auto *ptr = option_group.get();
734734
// move to App_p for overload resolution on older gcc versions
735735
App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
736+
// don't inherit the footer in option groups and clear the help flag by default
737+
app_ptr->footer_ = "";
738+
app_ptr->set_help_flag();
736739
add_subcommand(std::move(app_ptr));
737740
return ptr;
738741
}

include/CLI/impl/Config_inl.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
549549
bool isDefault = false;
550550
if(value.empty() && default_also) {
551551
if(!opt->get_default_str().empty()) {
552-
value = detail::convert_arg_for_ini(opt->get_default_str(), stringQuote, literalQuote, false);
552+
results_t res;
553+
opt->results(res);
554+
value = detail::ini_join(res, arraySeparator, arrayStart, arrayEnd, stringQuote, literalQuote);
553555
} else if(opt->get_expected_min() == 0) {
554556
value = "false";
555557
} else if(opt->get_run_callback_for_default() || !opt->get_required()) {

include/CLI/impl/Option_inl.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
686686
}
687687
}
688688

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

692693
result.pop_back();

tests/ConfigFileTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <tuple>
1515
#include <vector>
1616

17+
#include <array>
18+
1719
TEST_CASE("StringBased: convert_arg_for_ini", "[config]") {
1820

1921
CHECK("\"\"" == CLI::detail::convert_arg_for_ini(std::string{}));
@@ -4114,3 +4116,20 @@ TEST_CASE_METHOD(TApp, "RoundTripEmptyVector", "[config]") {
41144116
app.parse_from_stream(out);
41154117
CHECK(cv.empty());
41164118
}
4119+
4120+
TEST_CASE_METHOD(TApp, "RoundTripArrayFloat", "[config]") {
4121+
std::array<float, 2> cv{-1.0F, 1.0F};
4122+
app.add_option("-c", cv)->capture_default_str();
4123+
4124+
args = {};
4125+
4126+
run();
4127+
std::string configOut = app.config_to_str(true, true);
4128+
app.clear();
4129+
std::stringstream out(configOut);
4130+
cv[0] = -3.0F;
4131+
cv[1] = 4.0F;
4132+
app.parse_from_stream(out);
4133+
CHECK(cv[0] == -1.0F);
4134+
CHECK(cv[1] == 1.0F);
4135+
}

tests/HelpTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ TEST_CASE("THelp: FooterCallbackBoth", "[help]") {
8585
CHECK_THAT(help, Contains("foot!!!!"));
8686
}
8787

88+
/// @brief from github issue #1156
89+
TEST_CASE("THelp: FooterOptionGroup", "[help]") {
90+
CLI::App app{"My prog"};
91+
92+
app.footer("Report bugs to [email protected]");
93+
94+
app.add_option_group("group-a", "");
95+
96+
app.add_option_group("group-b", "");
97+
98+
std::string help = app.help();
99+
100+
auto footer_loc = help.find("[email protected]");
101+
auto footer_loc2 = help.find("[email protected]", footer_loc + 10);
102+
CHECK(footer_loc != std::string::npos);
103+
// should only see the footer once
104+
CHECK(footer_loc2 == std::string::npos);
105+
}
106+
88107
TEST_CASE("THelp: OptionalPositional", "[help]") {
89108
CLI::App app{"My prog", "program"};
90109

0 commit comments

Comments
 (0)