Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires and help all #530

Merged
merged 1 commit into from
Oct 28, 2020
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
11 changes: 7 additions & 4 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,10 +2252,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(); });
Expand Down
10 changes: 7 additions & 3 deletions include/CLI/StringTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down