1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 05:03:52 +00:00

Tighten up syntax from recent PR a bit

This commit is contained in:
Henry Fredrick Schreiner 2019-01-19 11:17:25 +01:00
parent 1933a21a6d
commit bd67a953b2

View File

@ -2023,27 +2023,19 @@ namespace FailureMessage {
/// Printout a clean, simple message on error (the default in CLI11 1.5+)
inline std::string simple(const App *app, const Error &e) {
const bool has_help = app->get_help_ptr() != nullptr;
const bool has_help_all = app->get_help_all_ptr() != nullptr;
std::string header = std::string(e.what()) + "\n";
std::vector<std::string> names;
if(has_help || has_help_all) {
header += "Run with ";
// Collect names
if(app->get_help_ptr() != nullptr)
names.push_back(app->get_help_ptr()->get_name());
if(has_help) {
header += app->get_help_ptr()->get_name();
}
if(app->get_help_all_ptr() != nullptr)
names.push_back(app->get_help_all_ptr()->get_name());
if(has_help_all) {
if(has_help) {
header += " or ";
}
header += app->get_help_all_ptr()->get_name();
}
header += " for more information.\n";
}
// If any names found, suggest those
if(!names.empty())
header += "Run with " + detail::join(names, " or ") + " for more information.\n";
return header;
}