Commit bd67a953b24bc2bf03e65c09204100d094e40d8b

Authored by Henry Fredrick Schreiner
1 parent 1933a21a

Tighten up syntax from recent PR a bit

Showing 1 changed file with 9 additions and 17 deletions
include/CLI/App.hpp
@@ -2023,27 +2023,19 @@ namespace FailureMessage { @@ -2023,27 +2023,19 @@ namespace FailureMessage {
2023 2023
2024 /// Printout a clean, simple message on error (the default in CLI11 1.5+) 2024 /// Printout a clean, simple message on error (the default in CLI11 1.5+)
2025 inline std::string simple(const App *app, const Error &e) { 2025 inline std::string simple(const App *app, const Error &e) {
2026 - const bool has_help = app->get_help_ptr() != nullptr;  
2027 - const bool has_help_all = app->get_help_all_ptr() != nullptr;  
2028 -  
2029 std::string header = std::string(e.what()) + "\n"; 2026 std::string header = std::string(e.what()) + "\n";
  2027 + std::vector<std::string> names;
2030 2028
2031 - if(has_help || has_help_all) {  
2032 - header += "Run with ";  
2033 -  
2034 - if(has_help) {  
2035 - header += app->get_help_ptr()->get_name();  
2036 - } 2029 + // Collect names
  2030 + if(app->get_help_ptr() != nullptr)
  2031 + names.push_back(app->get_help_ptr()->get_name());
2037 2032
2038 - if(has_help_all) {  
2039 - if(has_help) {  
2040 - header += " or ";  
2041 - }  
2042 - header += app->get_help_all_ptr()->get_name();  
2043 - } 2033 + if(app->get_help_all_ptr() != nullptr)
  2034 + names.push_back(app->get_help_all_ptr()->get_name());
2044 2035
2045 - header += " for more information.\n";  
2046 - } 2036 + // If any names found, suggest those
  2037 + if(!names.empty())
  2038 + header += "Run with " + detail::join(names, " or ") + " for more information.\n";
2047 2039
2048 return header; 2040 return header;
2049 } 2041 }