mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 14:03:52 +00:00
Deregister help if added previously
This commit is contained in:
parent
1b9aac85ca
commit
1c5c8391f7
@ -331,10 +331,10 @@ class App {
|
|||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a help flag, currently throws an error if already set
|
/// Add a help flag, replaced the existing one if present
|
||||||
Option *add_help_flag(std::string name, std::string description = "") {
|
Option *add_help_flag(std::string name, std::string description = "") {
|
||||||
if(help_ptr_)
|
if(help_ptr_ != nullptr)
|
||||||
throw IncorrectConstruction("Help flag already initialized");
|
remove_option(help_ptr_);
|
||||||
help_ptr_ = add_flag(name, description);
|
help_ptr_ = add_flag(name, description);
|
||||||
return help_ptr_;
|
return help_ptr_;
|
||||||
}
|
}
|
||||||
|
@ -286,8 +286,13 @@ TEST(THelp, SetLower) {
|
|||||||
TEST(THelp, OnlyOneHelp) {
|
TEST(THelp, OnlyOneHelp) {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
/* It is not supported to add more than one help flag. */
|
// It is not supported to have more than one help flag, last one wins
|
||||||
EXPECT_THROW(app.add_help_flag("--yelp", "Alias for help"), CLI::IncorrectConstruction);
|
app.add_help_flag("--help", "No short name allowed");
|
||||||
|
app.add_help_flag("--yelp", "Alias for help");
|
||||||
|
|
||||||
|
std::vector<std::string> input{"--help"};
|
||||||
|
EXPECT_THROW(app.parse(input), CLI::ExtrasError);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(THelp, NoHelp) {
|
TEST(THelp, NoHelp) {
|
||||||
@ -313,7 +318,6 @@ TEST(THelp, CustomHelp) {
|
|||||||
|
|
||||||
CLI::Option *help_option = app.add_help_flag("--yelp", "display help and exit");
|
CLI::Option *help_option = app.add_help_flag("--yelp", "display help and exit");
|
||||||
EXPECT_EQ(app.get_help_ptr(), help_option);
|
EXPECT_EQ(app.get_help_ptr(), help_option);
|
||||||
EXPECT_THROW(app.add_help_flag("--help", "Alias for yelp"), CLI::IncorrectConstruction);
|
|
||||||
|
|
||||||
std::string help = app.help();
|
std::string help = app.help();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user