aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-07-01 20:31:39 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-07-01 20:31:39 +0200
commit6ff9aa8df7ce8266147f74c65e2cc529a1e72ce0 (patch)
tree204905fe5f1e570ad7f42e75df8d2b9a72fbef6e
parentd746503e5c6fafd0fb6b2a4e6527c12cfc626637 (diff)
Don't process an option if any of its arguments need completion
-rw-r--r--src/libutil/args.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index b16a2e213..986c5d1cd 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -123,17 +123,21 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
auto process = [&](const std::string & name, const Flag & flag) -> bool {
++pos;
std::vector<std::string> args;
+ bool anyCompleted = false;
for (size_t n = 0 ; n < flag.handler.arity; ++n) {
if (pos == end) {
if (flag.handler.arity == ArityAny) break;
throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity);
}
if (flag.completer)
- if (auto prefix = needsCompletion(*pos))
+ if (auto prefix = needsCompletion(*pos)) {
+ anyCompleted = true;
flag.completer(n, *prefix);
+ }
args.push_back(*pos++);
}
- flag.handler.fun(std::move(args));
+ if (!anyCompleted)
+ flag.handler.fun(std::move(args));
return true;
};