1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 05:03:52 +00:00

Dropping the error if a bool flag is set multiple times

This commit is contained in:
Henry Fredrick Schreiner 2017-11-16 13:04:37 -05:00 committed by Henry Schreiner
parent 3de7832c3d
commit 0a35db8f00
3 changed files with 7 additions and 5 deletions

View File

@ -351,16 +351,16 @@ class App {
return opt; 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> template <typename T, enable_if_t<is_bool<T>::value, detail::enabler> = detail::dummy>
Option *add_flag(std::string name, Option *add_flag(std::string name,
T &count, ///< A varaible holding true if passed T &count, ///< A varaible holding true if passed
std::string description = "") { std::string description = "") {
count = false; count = false;
CLI::callback_t fun = [&count](CLI::results_t res) { CLI::callback_t fun = [&count](CLI::results_t) {
count = true; count = true;
return res.size() == 1; return true;
}; };
Option *opt = add_option(name, fun, description, false); Option *opt = add_option(name, fun, description, false);

View File

@ -154,7 +154,8 @@ TEST_F(TApp, BoolAndIntFlags) {
app.reset(); app.reset();
args = {"-b", "-b"}; args = {"-b", "-b"};
EXPECT_THROW(run(), CLI::ConversionError); EXPECT_NO_THROW(run());
EXPECT_TRUE(bflag);
app.reset(); app.reset();
bflag = false; bflag = false;

View File

@ -438,7 +438,8 @@ TEST_F(TApp, IniFlagNumbers) {
out << "flag=3" << std::endl; out << "flag=3" << std::endl;
} }
EXPECT_THROW(run(), CLI::ConversionError); EXPECT_NO_THROW(run());
EXPECT_TRUE(boo);
} }
TEST_F(TApp, IniFlagDual) { TEST_F(TApp, IniFlagDual) {