Skip to content

Commit

Permalink
Dropping the error if a bool flag is set multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Nov 18, 2017
1 parent 3de7832 commit 0a35db8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,16 @@ class App {
return opt;
}

/// Bool version only allows the flag once
/// Bool version
template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy>
Option *add_flag(std::string name,
T &count, ///< A varaible holding true if passed
std::string description = "") {

count = false;
CLI::callback_t fun = [&count](CLI::results_t res) {
CLI::callback_t fun = [&count](CLI::results_t) {
count = true;
return res.size() == 1;
return true;
};

Option *opt = add_option(name, fun, description, false);
Expand Down
3 changes: 2 additions & 1 deletion tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ TEST_F(TApp, BoolAndIntFlags) {
app.reset();

args = {"-b", "-b"};
EXPECT_THROW(run(), CLI::ConversionError);
EXPECT_NO_THROW(run());
EXPECT_TRUE(bflag);

app.reset();
bflag = false;
Expand Down
3 changes: 2 additions & 1 deletion tests/IniTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ TEST_F(TApp, IniFlagNumbers) {
out << "flag=3" << std::endl;
}

EXPECT_THROW(run(), CLI::ConversionError);
EXPECT_NO_THROW(run());
EXPECT_TRUE(boo);
}

TEST_F(TApp, IniFlagDual) {
Expand Down

0 comments on commit 0a35db8

Please sign in to comment.