aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/args.cc
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-06-20 04:15:38 +0200
committerNaïm Favier <n@monade.li>2022-07-11 15:13:51 +0200
commit711b2e1f48316d80853635408c518e3562a1fa37 (patch)
treedcb298bf9a252344e8e7dd947a5d029e4e6e131d /src/libutil/args.cc
parentd6d0e781bbade76f6ea3f310cb36973f4013826d (diff)
Fix flake input completion for `InstallablesCommand`s
Defers completion of flake inputs until the whole command line is parsed so that we know what flakes we need to complete the inputs of. Previously, `nix build flake --update-input <Tab>` always behaved like `nix build . --update-input <Tab>`.
Diffstat (limited to 'src/libutil/args.cc')
-rw-r--r--src/libutil/args.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 4b8c55686..44b63f0f6 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -124,7 +124,7 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
bool anyCompleted = false;
for (size_t n = 0 ; n < flag.handler.arity; ++n) {
if (pos == end) {
- if (flag.handler.arity == ArityAny) break;
+ if (flag.handler.arity == ArityAny || anyCompleted) break;
throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity);
}
if (auto prefix = needsCompletion(*pos)) {
@@ -362,6 +362,14 @@ bool MultiCommand::processArgs(const Strings & args, bool finish)
return Args::processArgs(args, finish);
}
+void MultiCommand::completionHook()
+{
+ if (command)
+ return command->second->completionHook();
+ else
+ return Args::completionHook();
+}
+
nlohmann::json MultiCommand::toJSON()
{
auto cmds = nlohmann::json::object();