From a78f5bcdcf8d34f5191c01856445a256497b4a7f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 13 Nov 2018 17:12:48 +0100 Subject: [PATCH] Dropping links if option removed (#179) --- include/CLI/App.hpp | 8 +++++++- include/CLI/Option.hpp | 30 +++++++++++++++++++++++++++--- tests/AppTest.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 99bc97742..7309deb3a 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -781,6 +781,12 @@ class App { /// Removes an option from the App. Takes an option pointer. Returns true if found and removed. bool remove_option(Option *opt) { + // Make sure no links exist + for(Option_p &op : options_) { + op->remove_needs(opt); + op->remove_excludes(opt); + } + auto iterator = std::find_if(std::begin(options_), std::end(options_), [opt](const Option_p &v) { return v.get() == opt; }); if(iterator != std::end(options_)) { @@ -1356,7 +1362,7 @@ class App { throw RequiredError(opt->get_name()); } // Requires - for(const Option *opt_req : opt->requires_) + for(const Option *opt_req : opt->needs_) if(opt->count() > 0 && opt_req->count() == 0) throw RequiresError(opt->get_name(), opt_req->get_name()); // Excludes diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index a5f046a22..c37e39f7b 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -200,7 +200,7 @@ class Option : public OptionBase