mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +00:00
Reword help message to include help_all flag (#197)
* Reword help message to include help_all flag * Adding test for combined simple message
This commit is contained in:
parent
c65d9fdcb2
commit
1933a21a6d
@ -2023,9 +2023,28 @@ namespace FailureMessage {
|
|||||||
|
|
||||||
/// Printout a clean, simple message on error (the default in CLI11 1.5+)
|
/// Printout a clean, simple message on error (the default in CLI11 1.5+)
|
||||||
inline std::string simple(const App *app, const Error &e) {
|
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::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;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,6 +530,34 @@ TEST_F(CapturedHelp, NormalError) {
|
|||||||
EXPECT_THAT(err.str(), HasSubstr("for more information"));
|
EXPECT_THAT(err.str(), HasSubstr("for more information"));
|
||||||
EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
|
EXPECT_THAT(err.str(), Not(HasSubstr("ExtrasError")));
|
||||||
EXPECT_THAT(err.str(), HasSubstr("Thing"));
|
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")));
|
EXPECT_THAT(err.str(), Not(HasSubstr("Usage")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user