diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 8965159d9..482b1b749 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -2253,10 +2253,13 @@ class App { } if(require_option_min_ > used_options || (require_option_max_ > 0 && require_option_max_ < used_options)) { - auto option_list = detail::join(options_, [](const Option_p &ptr) { return ptr->get_name(false, true); }); - if(option_list.compare(0, 10, "-h,--help,") == 0) { - option_list.erase(0, 10); - } + auto option_list = detail::join(options_, [this](const Option_p &ptr) { + if(ptr.get() == help_ptr_ || ptr.get() == help_all_ptr_) { + return std::string{}; + } + return ptr->get_name(false, true); + }); + auto subc_list = get_subcommands([](App *app) { return ((app->get_name().empty()) && (!app->disabled_)); }); if(!subc_list.empty()) { option_list += "," + detail::join(subc_list, [](const App *app) { return app->get_display_name(); }); diff --git a/include/CLI/StringTools.hpp b/include/CLI/StringTools.hpp index 1500b8219..e1f0df7e0 100644 --- a/include/CLI/StringTools.hpp +++ b/include/CLI/StringTools.hpp @@ -76,10 +76,14 @@ std::string join(const T &v, Callable func, std::string delim = ",") { std::ostringstream s; auto beg = std::begin(v); auto end = std::end(v); - if(beg != end) - s << func(*beg++); + auto loc = s.tellp(); while(beg != end) { - s << delim << func(*beg++); + auto nloc = s.tellp(); + if(nloc > loc) { + s << delim; + loc = nloc; + } + s << func(*beg++); } return s.str(); } diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index b0ca787af..6742a5052 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -135,11 +135,14 @@ TEST_F(TApp, RequireOptionsError) { app.add_flag("-c"); app.add_flag("--q"); app.add_flag("--this,--that"); + app.set_help_flag("-h,--help"); + app.set_help_all_flag("--help_all"); app.require_option(1, 2); try { app.parse("-c --q --this --that"); } catch(const CLI::RequiredError &re) { EXPECT_THAT(re.what(), Not(HasSubstr("-h,--help"))); + EXPECT_THAT(re.what(), Not(HasSubstr("help_all"))); } EXPECT_NO_THROW(app.parse("-c --q"));