1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Add --arg-from-stdin to read an argument from stdin

This commit is contained in:
Eelco Dolstra 2024-03-01 14:39:42 +01:00
parent 291b10c607
commit 8ce1f6800b
3 changed files with 16 additions and 1 deletions

View file

@ -40,6 +40,14 @@ MixEvalArgs::MixEvalArgs()
.completer = completePath
});
addFlag({
.longName = "arg-from-stdin",
.description = "Pass the contents of stdin as the argument *name* to Nix functions.",
.category = category,
.labels = {"name"},
.handler = {[&](std::string name) { autoArgs.insert_or_assign(name, AutoArg{AutoArgStdin{}}); }},
});
addFlag({
.longName = "include",
.shortName = 'I',
@ -174,6 +182,9 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
},
[&](const AutoArgFile & arg) {
v->mkString(readFile(arg.path));
},
[&](const AutoArgStdin & arg) {
v->mkString(readFile(STDIN_FILENO));
}
}, arg);
res.insert(state.symbols.create(name), v);