aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/bundle.cc4
-rw-r--r--src/nix/flake.cc14
-rw-r--r--src/nix/main.cc27
-rw-r--r--src/nix/registry.cc4
-rw-r--r--src/nix/why-depends.cc8
5 files changed, 26 insertions, 31 deletions
diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc
index fbc83b08e..504e35c81 100644
--- a/src/nix/bundle.cc
+++ b/src/nix/bundle.cc
@@ -21,8 +21,8 @@ struct CmdBundle : InstallableValueCommand
.description = fmt("Use a custom bundler instead of the default (`%s`).", bundler),
.labels = {"flake-url"},
.handler = {&bundler},
- .completer = {[&](size_t, std::string_view prefix) {
- completeFlakeRef(getStore(), prefix);
+ .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
+ completeFlakeRef(completions, getStore(), prefix);
}}
});
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 6b3012558..dde4b43bd 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -36,8 +36,8 @@ public:
.label = "flake-url",
.optional = true,
.handler = {&flakeUrl},
- .completer = {[&](size_t, std::string_view prefix) {
- completeFlakeRef(getStore(), prefix);
+ .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
+ completeFlakeRef(completions, getStore(), prefix);
}}
});
}
@@ -52,9 +52,12 @@ public:
return flake::lockFlake(*getEvalState(), getFlakeRef(), lockFlags);
}
- std::vector<std::string> getFlakesForCompletion() override
+ std::vector<FlakeRef> getFlakeRefsForCompletion() override
{
- return {flakeUrl};
+ return {
+ // Like getFlakeRef but with expandTilde calld first
+ parseFlakeRef(expandTilde(flakeUrl), absPath("."))
+ };
}
};
@@ -777,8 +780,9 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
.description = "The template to use.",
.labels = {"template"},
.handler = {&templateUrl},
- .completer = {[&](size_t, std::string_view prefix) {
+ .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
completeFlakeRefWithFragment(
+ completions,
getEvalState(),
lockFlags,
defaultTemplateAttrPathsPrefixes,
diff --git a/src/nix/main.cc b/src/nix/main.cc
index a9c6c6ea2..e033a5f5a 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -1,5 +1,6 @@
#include <algorithm>
+#include "args/root.hh"
#include "command.hh"
#include "common-args.hh"
#include "eval.hh"
@@ -75,7 +76,7 @@ static bool haveInternet()
std::string programPath;
-struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
+struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
{
bool useNet = true;
bool refresh = false;
@@ -253,10 +254,7 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)
static NixArgs & getNixArgs(Command & cmd)
{
- assert(cmd.parent);
- MultiCommand * toplevel = cmd.parent;
- while (toplevel->parent) toplevel = toplevel->parent;
- return dynamic_cast<NixArgs &>(*toplevel);
+ return dynamic_cast<NixArgs &>(cmd.getRoot());
}
struct CmdHelp : Command
@@ -424,16 +422,16 @@ void mainWrapped(int argc, char * * argv)
Finally printCompletions([&]()
{
- if (completions) {
- switch (completionType) {
- case ctNormal:
+ if (args.completions) {
+ switch (args.completions->type) {
+ case Completions::Type::Normal:
logger->cout("normal"); break;
- case ctFilenames:
+ case Completions::Type::Filenames:
logger->cout("filenames"); break;
- case ctAttrs:
+ case Completions::Type::Attrs:
logger->cout("attrs"); break;
}
- for (auto & s : *completions)
+ for (auto & s : args.completions->completions)
logger->cout(s.completion + "\t" + trim(s.description));
}
});
@@ -441,7 +439,7 @@ void mainWrapped(int argc, char * * argv)
try {
args.parseCmdline(argvToStrings(argc, argv));
} catch (UsageError &) {
- if (!args.helpRequested && !completions) throw;
+ if (!args.helpRequested && !args.completions) throw;
}
if (args.helpRequested) {
@@ -458,10 +456,7 @@ void mainWrapped(int argc, char * * argv)
return;
}
- if (completions) {
- args.completionHook();
- return;
- }
+ if (args.completions) return;
if (args.showVersion) {
printVersion(programName);
diff --git a/src/nix/registry.cc b/src/nix/registry.cc
index cb94bbd31..f509ccae8 100644
--- a/src/nix/registry.cc
+++ b/src/nix/registry.cc
@@ -175,8 +175,8 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
.label = "locked",
.optional = true,
.handler = {&locked},
- .completer = {[&](size_t, std::string_view prefix) {
- completeFlakeRef(getStore(), prefix);
+ .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
+ completeFlakeRef(completions, getStore(), prefix);
}}
});
}
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index 592de773c..055cf6d0d 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -38,17 +38,13 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
expectArgs({
.label = "package",
.handler = {&_package},
- .completer = {[&](size_t, std::string_view prefix) {
- completeInstallable(prefix);
- }}
+ .completer = getCompleteInstallable(),
});
expectArgs({
.label = "dependency",
.handler = {&_dependency},
- .completer = {[&](size_t, std::string_view prefix) {
- completeInstallable(prefix);
- }}
+ .completer = getCompleteInstallable(),
});
addFlag({