mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-05 06:33:52 +00:00
Adding corrected positional help
This commit is contained in:
parent
6d445ff03d
commit
f6e771a248
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
///@}
|
||||
};
|
||||
|
||||
|
||||
|
@ -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"};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user