From bd67a953b24bc2bf03e65c09204100d094e40d8b Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sat, 19 Jan 2019 11:17:25 +0100 Subject: [PATCH] Tighten up syntax from recent PR a bit --- include/CLI/App.hpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 800e6579..ad2edc73 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -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 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; }