mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Removing requires (#112)
This commit is contained in:
parent
b957301c3a
commit
bc61342d8e
@ -313,26 +313,6 @@ class Option : public OptionBase<Option> {
|
||||
return needs(opt1, args...);
|
||||
}
|
||||
|
||||
#ifndef CLI11_CPP20
|
||||
/// Sets required options \deprecated
|
||||
CLI11_DEPRECATED("Use needs instead of requires (eventual keyword clash)")
|
||||
Option *requires(Option *opt) { return needs(opt); }
|
||||
|
||||
/// Can find a string if needed \deprecated
|
||||
template <typename T = App> Option *requires(std::string opt_name) {
|
||||
for(const Option_p &opt : dynamic_cast<T *>(parent_)->options_)
|
||||
if(opt.get() != this && opt->check_name(opt_name))
|
||||
return needs(opt.get());
|
||||
throw IncorrectConstruction::MissingOption(opt_name);
|
||||
}
|
||||
|
||||
/// Any number supported, any mix of string and Opt \deprecated
|
||||
template <typename A, typename B, typename... ARG> Option *requires(A opt, B opt1, ARG... args) {
|
||||
requires(opt);
|
||||
return requires(opt1, args...);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Sets excluded options
|
||||
Option *excludes(Option *opt) {
|
||||
excludes_.insert(opt);
|
||||
|
@ -1234,43 +1234,6 @@ TEST_F(TApp, NeedsMixedFlags) {
|
||||
run();
|
||||
}
|
||||
|
||||
#ifndef CLI11_CPP20
|
||||
|
||||
TEST_F(TApp, RequiresMixedFlags) {
|
||||
CLI::Option *opt1 = app.add_flag("--opt1");
|
||||
app.add_flag("--opt2");
|
||||
app.add_flag("--opt3");
|
||||
app.add_flag("--optall")->requires(opt1, "--opt2", "--opt3");
|
||||
|
||||
run();
|
||||
|
||||
app.reset();
|
||||
args = {"--opt1"};
|
||||
run();
|
||||
|
||||
app.reset();
|
||||
args = {"--opt2"};
|
||||
run();
|
||||
|
||||
app.reset();
|
||||
args = {"--optall"};
|
||||
EXPECT_THROW(run(), CLI::RequiresError);
|
||||
|
||||
app.reset();
|
||||
args = {"--optall", "--opt1"};
|
||||
EXPECT_THROW(run(), CLI::RequiresError);
|
||||
|
||||
app.reset();
|
||||
args = {"--optall", "--opt2", "--opt1"};
|
||||
EXPECT_THROW(run(), CLI::RequiresError);
|
||||
|
||||
app.reset();
|
||||
args = {"--optall", "--opt1", "--opt2", "--opt3"};
|
||||
run();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_F(TApp, NeedsChainedFlags) {
|
||||
CLI::Option *opt1 = app.add_flag("--opt1");
|
||||
CLI::Option *opt2 = app.add_flag("--opt2")->needs(opt1);
|
||||
|
@ -168,13 +168,6 @@ TEST_F(TApp, IncorrectConstructionNeedsCannotFind) {
|
||||
EXPECT_THROW(cat->needs("--nothing"), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
#ifndef CLI11_CPP20
|
||||
TEST_F(TApp, IncorrectConstructionRequiresCannotFind) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->requires("--nothing"), CLI::IncorrectConstruction);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
||||
|
Loading…
x
Reference in New Issue
Block a user