mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +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...);
|
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
|
/// Sets excluded options
|
||||||
Option *excludes(Option *opt) {
|
Option *excludes(Option *opt) {
|
||||||
excludes_.insert(opt);
|
excludes_.insert(opt);
|
||||||
|
@ -1234,43 +1234,6 @@ TEST_F(TApp, NeedsMixedFlags) {
|
|||||||
run();
|
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) {
|
TEST_F(TApp, NeedsChainedFlags) {
|
||||||
CLI::Option *opt1 = app.add_flag("--opt1");
|
CLI::Option *opt1 = app.add_flag("--opt1");
|
||||||
CLI::Option *opt2 = app.add_flag("--opt2")->needs(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);
|
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) {
|
TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
|
||||||
auto cat = app.add_flag("--cat");
|
auto cat = app.add_flag("--cat");
|
||||||
EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user