mirror of
https://github.com/NixOS/nix.git
synced 2025-12-16 14:01:05 +01:00
Add completion for --update-input
This commit is contained in:
parent
9ef6048d78
commit
6470450ab4
7 changed files with 45 additions and 7 deletions
|
|
@ -18,6 +18,17 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
void completeFlakeInputPath(
|
||||
ref<EvalState> evalState,
|
||||
const FlakeRef & flakeRef,
|
||||
std::string_view prefix)
|
||||
{
|
||||
auto flake = flake::getFlake(*evalState, flakeRef, true);
|
||||
for (auto & input : flake.inputs)
|
||||
if (hasPrefix(input.first, prefix))
|
||||
completions->insert(input.first);
|
||||
}
|
||||
|
||||
MixFlakeOptions::MixFlakeOptions()
|
||||
{
|
||||
addFlag({
|
||||
|
|
@ -56,6 +67,10 @@ MixFlakeOptions::MixFlakeOptions()
|
|||
.labels = {"input-path"},
|
||||
.handler = {[&](std::string s) {
|
||||
lockFlags.inputUpdates.insert(flake::parseInputPath(s));
|
||||
}},
|
||||
.completer = {[&](size_t, std::string_view prefix) {
|
||||
if (auto flakeRef = getFlakeRefForCompletion())
|
||||
completeFlakeInputPath(getEvalState(), *flakeRef, prefix);
|
||||
}}
|
||||
});
|
||||
|
||||
|
|
@ -707,6 +722,16 @@ void InstallablesCommand::prepare()
|
|||
installables = parseInstallables(getStore(), _installables);
|
||||
}
|
||||
|
||||
std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion()
|
||||
{
|
||||
if (_installables.empty()) {
|
||||
if (useDefaultInstallables())
|
||||
return parseFlakeRef(".", absPath("."));
|
||||
return {};
|
||||
}
|
||||
return parseFlakeRef(_installables.front(), absPath("."));
|
||||
}
|
||||
|
||||
InstallableCommand::InstallableCommand()
|
||||
{
|
||||
expectArgs({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue