diff --git a/examples/simple.cpp b/examples/simple.cpp index 70bd87c4..612fd9e0 100644 --- a/examples/simple.cpp +++ b/examples/simple.cpp @@ -8,7 +8,10 @@ int main(int argc, char **argv) { CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); int count; - CLI::Option *copt = app.add_flag("-c,--count", count, "Counter"); + CLI::Option *copt = app.add_option("-c,--count", count, "Counter"); + + int v; + CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times"); double value; // = 3.14; app.add_option("-d,--double", value, "Some Value"); @@ -19,6 +22,7 @@ int main(int argc, char **argv) { << ", opt count: " << opt->count() << std::endl; std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") << ", opt count: " << copt->count() << std::endl; + std::cout << "Recieved flag: " << v << " (" << flag->count() << ") times\n"; std::cout << "Some value: " << value << std::endl; return 0; diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 3b653086..322c5763 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -1196,7 +1196,9 @@ class App { if(num_left_over > 0) { args = remaining(false); std::reverse(std::begin(args), std::end(args)); - throw ExtrasError("[" + detail::rjoin(args, " ") + "]"); + throw ExtrasError((args.size() > 1 ? "The following argument was not expected: " + : "The following arguments were not expected: ") + + detail::rjoin(args, " ")); } } } @@ -1415,7 +1417,7 @@ class App { args.pop_back(); already_ate_one = true; } - } else + } else { while(num > 0 && !args.empty()) { num--; std::string current_ = args.back(); @@ -1424,6 +1426,12 @@ class App { parse_order_.push_back(op.get()); } + if(num > 0) { + throw RequiredError(op->single_name() + ": " + std::to_string(num) + " required " + + op->get_type_name() + " missing"); + } + } + if(!rest.empty()) { rest = "-" + rest; args.push_back(rest); @@ -1499,6 +1507,10 @@ class App { parse_order_.push_back(op.get()); args.pop_back(); } + if(num > 0) { + throw RequiredError(op->single_name() + ": " + std::to_string(num) + " required " + + op->get_type_name() + " missing"); + } } return; } diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index a71f5fac..477a9512 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -551,6 +551,9 @@ class Option : public OptionBase