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

Add --arg-from-file for reading a string from a file

This commit is contained in:
Eelco Dolstra 2024-03-01 14:35:27 +01:00
parent d72ee91d07
commit 291b10c607
3 changed files with 22 additions and 1 deletions

View file

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