Skip to content

Commit

Permalink
Removing requires (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Apr 25, 2018
1 parent b957301 commit bc61342
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 64 deletions.
20 changes: 0 additions & 20 deletions include/CLI/Option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 0 additions & 37 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions tests/CreationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bc61342

Please sign in to comment.