mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Adding REQUIRED and Needs, using simple name more often
This commit is contained in:
parent
c63288a91c
commit
067bb43a84
@ -3,9 +3,13 @@
|
||||
* Make unlimited positionals vs. unlimited options more intuitive [#102]
|
||||
* Add missing getters `get_options` and `get_description` to App [#105]
|
||||
* The app name now can be set, and will override the auto name if present [#105]
|
||||
* Add `(REQUIRED)` for required options [#104]
|
||||
* Print simple name for Needs/Excludes [#104]
|
||||
* Use Needs instead of Requires in help print [#104]
|
||||
|
||||
[#102]: https://github.com/CLIUtils/CLI11/issues/102
|
||||
[#105]: https://github.com/CLIUtils/CLI11/issues/105
|
||||
[#104]: https://github.com/CLIUtils/CLI11/pull/104
|
||||
|
||||
|
||||
## Version 1.5: Optionals
|
||||
|
@ -295,7 +295,7 @@ class Option : public OptionBase<Option> {
|
||||
Option *needs(Option *opt) {
|
||||
auto tup = requires_.insert(opt);
|
||||
if(!tup.second)
|
||||
throw OptionAlreadyAdded::Requires(get_name(), opt->get_name());
|
||||
throw OptionAlreadyAdded::Requires(single_name(), opt->single_name());
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -503,18 +503,20 @@ class Option : public OptionBase<Option> {
|
||||
out << " x " << get_expected();
|
||||
if(get_expected() == -1)
|
||||
out << " ...";
|
||||
if(get_required())
|
||||
out << " (REQUIRED)";
|
||||
}
|
||||
if(!envname_.empty())
|
||||
out << " (env:" << envname_ << ")";
|
||||
if(!requires_.empty()) {
|
||||
out << " Requires:";
|
||||
out << " Needs:";
|
||||
for(const Option *opt : requires_)
|
||||
out << " " << opt->get_name();
|
||||
out << " " << opt->single_name();
|
||||
}
|
||||
if(!excludes_.empty()) {
|
||||
out << " Excludes:";
|
||||
for(const Option *opt : excludes_)
|
||||
out << " " << opt->get_name();
|
||||
out << " " << opt->single_name();
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ TEST(THelp, Needs) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("Requires: --op1"));
|
||||
EXPECT_THAT(help, HasSubstr("Needs: --op1"));
|
||||
}
|
||||
|
||||
TEST(THelp, NeedsPositional) {
|
||||
@ -176,7 +176,7 @@ TEST(THelp, NeedsPositional) {
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("Positionals:"));
|
||||
EXPECT_THAT(help, HasSubstr("Requires: op1"));
|
||||
EXPECT_THAT(help, HasSubstr("Needs: op1"));
|
||||
}
|
||||
|
||||
TEST(THelp, Excludes) {
|
||||
@ -495,3 +495,24 @@ TEST(THelp, AccessDescription) {
|
||||
|
||||
EXPECT_EQ(app.get_description(), "My description goes here");
|
||||
}
|
||||
|
||||
TEST(THelp, CleanNeeds) {
|
||||
CLI::App app;
|
||||
|
||||
int x;
|
||||
auto a_name = app.add_option("-a,--alpha", x);
|
||||
app.add_option("-b,--boo", x)->needs(a_name);
|
||||
|
||||
EXPECT_THAT(app.help(), Not(HasSubstr("Requires")));
|
||||
EXPECT_THAT(app.help(), Not(HasSubstr("Needs: -a,--alpha")));
|
||||
EXPECT_THAT(app.help(), HasSubstr("Needs: --alpha"));
|
||||
}
|
||||
|
||||
TEST(THelp, RequiredPrintout) {
|
||||
CLI::App app;
|
||||
|
||||
int x;
|
||||
app.add_option("-a,--alpha", x)->required();
|
||||
|
||||
EXPECT_THAT(app.help(), HasSubstr("(REQUIRED)"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user