Commit 1933a21a6d34eb986dc0ea144a6f422fce0c65ab

Authored by nurelin
Committed by Henry Schreiner
1 parent c65d9fdc

Reword help message to include help_all flag (#197)

* Reword help message to include help_all flag

* Adding test for combined simple message
include/CLI/App.hpp
... ... @@ -2023,9 +2023,28 @@ namespace FailureMessage {
2023 2023  
2024 2024 /// Printout a clean, simple message on error (the default in CLI11 1.5+)
2025 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 +
2026 2029 std::string header = std::string(e.what()) + "\n";
2027   - if(app->get_help_ptr() != nullptr)
2028   - header += "Run with " + app->get_help_ptr()->get_name() + " for more information.\n";
  2030 +
  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 + }
  2037 +
  2038 + if(has_help_all) {
  2039 + if(has_help) {
  2040 + header += " or ";
  2041 + }
  2042 + header += app->get_help_all_ptr()->get_name();
  2043 + }
  2044 +
  2045 + header += " for more information.\n";
  2046 + }
  2047 +
2029 2048 return header;
2030 2049 }
2031 2050  
... ...
tests/HelpTest.cpp
... ... @@ -530,6 +530,34 @@ TEST_F(CapturedHelp, NormalError) {
530 530 EXPECT_THAT(err.str(), HasSubstr("for more information"));
531 531 EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
532 532 EXPECT_THAT(err.str(), HasSubstr("Thing"));
  533 + EXPECT_THAT(err.str(), Not(HasSubstr(" or ")));
  534 + EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
  535 +}
  536 +
  537 +TEST_F(CapturedHelp, DoubleError) {
  538 + app.set_help_all_flag("--help-all");
  539 + EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError));
  540 + EXPECT_EQ(out.str(), "");
  541 + EXPECT_THAT(err.str(), HasSubstr("for more information"));
  542 + EXPECT_THAT(err.str(), HasSubstr(" --help "));
  543 + EXPECT_THAT(err.str(), HasSubstr(" --help-all "));
  544 + EXPECT_THAT(err.str(), HasSubstr(" or "));
  545 + EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
  546 + EXPECT_THAT(err.str(), HasSubstr("Thing"));
  547 + EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
  548 +}
  549 +
  550 +TEST_F(CapturedHelp, AllOnlyError) {
  551 + app.set_help_all_flag("--help-all");
  552 + app.set_help_flag();
  553 + EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError));
  554 + EXPECT_EQ(out.str(), "");
  555 + EXPECT_THAT(err.str(), HasSubstr("for more information"));
  556 + EXPECT_THAT(err.str(), Not(HasSubstr(" --help ")));
  557 + EXPECT_THAT(err.str(), HasSubstr(" --help-all "));
  558 + EXPECT_THAT(err.str(), Not(HasSubstr(" or ")));
  559 + EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
  560 + EXPECT_THAT(err.str(), HasSubstr("Thing"));
533 561 EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
534 562 }
535 563  
... ...