diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 307b1783..dbbc6be6 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -593,7 +593,7 @@ public: //if(detail::to_lower(opt->get_group()) == "hidden") // continue; out << " " << opt->help_positional(); - if(opt->has_description()) + if(opt->_has_help_positional()) pos=true; } @@ -612,7 +612,7 @@ public: for(const Option_p &opt : options_) { if(detail::to_lower(opt->get_group()) == "hidden") continue; - if(opt->get_positional() && opt->has_description()) + if(opt->_has_help_positional()) detail::format_help(out, opt->help_pname(), opt->get_description(), wid); } out << std::endl; diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index 15693b7f..291dc421 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -364,6 +364,7 @@ public: } + ///@} /// @name Parser tools ///@{ @@ -451,6 +452,16 @@ public: ///@} + protected: + + + /// @name App Helpers + ///@{ + /// Can print positional name detailed option if true + bool _has_help_positional() const { + return get_positional() && (has_description() || requires_.size()>0 || excludes_.size()>0 ); + } + ///@} }; diff --git a/tests/HelpTest.cpp b/tests/HelpTest.cpp index 54d667ec..3bf8596c 100644 --- a/tests/HelpTest.cpp +++ b/tests/HelpTest.cpp @@ -149,6 +149,20 @@ TEST(THelp, Requires) { EXPECT_THAT(help, HasSubstr("Requires: --op1")); } +TEST(THelp, RequiresPositional) { + CLI::App app{"My prog"}; + + int x,y; + + CLI::Option* op1 = app.add_option("op1", x, "one"); + app.add_option("op2", y, "two")->requires(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Requires: op1")); +} + TEST(THelp, Excludes) { CLI::App app{"My prog"}; @@ -160,6 +174,19 @@ TEST(THelp, Excludes) { EXPECT_THAT(help, HasSubstr("Excludes: --op1")); } +TEST(THelp, ExcludesPositional) { + CLI::App app{"My prog"}; + + int x,y; + + CLI::Option* op1 = app.add_option("op1", x); + app.add_option("op2", y)->excludes(op1); + + std::string help = app.help(); + + EXPECT_THAT(help, HasSubstr("Positionals:")); + EXPECT_THAT(help, HasSubstr("Excludes: op1")); +} TEST(THelp, Subcom) { CLI::App app{"My prog"};