mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 20:53:52 +00:00
Dropping the error if a bool flag is set multiple times
This commit is contained in:
parent
3de7832c3d
commit
0a35db8f00
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user