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

Reword help message to include help_all flag #197

Merged
merged 2 commits into from
Jan 18, 2019
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
23 changes: 21 additions & 2 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,28 @@ 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";
if(app->get_help_ptr() != nullptr)
header += "Run with " + app->get_help_ptr()->get_name() + " for more information.\n";

if(has_help || has_help_all) {
header += "Run with ";

if(has_help) {
header += app->get_help_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";
}

return header;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/HelpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,34 @@ TEST_F(CapturedHelp, NormalError) {
EXPECT_THAT(err.str(), HasSubstr("for more information"));
EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
EXPECT_THAT(err.str(), HasSubstr("Thing"));
EXPECT_THAT(err.str(), Not(HasSubstr(" or ")));
EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
}

TEST_F(CapturedHelp, DoubleError) {
app.set_help_all_flag("--help-all");
EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError));
EXPECT_EQ(out.str(), "");
EXPECT_THAT(err.str(), HasSubstr("for more information"));
EXPECT_THAT(err.str(), HasSubstr(" --help "));
EXPECT_THAT(err.str(), HasSubstr(" --help-all "));
EXPECT_THAT(err.str(), HasSubstr(" or "));
EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
EXPECT_THAT(err.str(), HasSubstr("Thing"));
EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
}

TEST_F(CapturedHelp, AllOnlyError) {
app.set_help_all_flag("--help-all");
app.set_help_flag();
EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError));
EXPECT_EQ(out.str(), "");
EXPECT_THAT(err.str(), HasSubstr("for more information"));
EXPECT_THAT(err.str(), Not(HasSubstr(" --help ")));
EXPECT_THAT(err.str(), HasSubstr(" --help-all "));
EXPECT_THAT(err.str(), Not(HasSubstr(" or ")));
EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
EXPECT_THAT(err.str(), HasSubstr("Thing"));
EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
}

Expand Down