mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-12-01 18:16:14 +02:00
Add --arg-from-stdin to read an argument from stdin
This commit is contained in:
parent
291b10c607
commit
8ce1f6800b
3 changed files with 16 additions and 1 deletions
|
@ -40,6 +40,14 @@ MixEvalArgs::MixEvalArgs()
|
||||||
.completer = completePath
|
.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({
|
addFlag({
|
||||||
.longName = "include",
|
.longName = "include",
|
||||||
.shortName = 'I',
|
.shortName = 'I',
|
||||||
|
@ -174,6 +182,9 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
||||||
},
|
},
|
||||||
[&](const AutoArgFile & arg) {
|
[&](const AutoArgFile & arg) {
|
||||||
v->mkString(readFile(arg.path));
|
v->mkString(readFile(arg.path));
|
||||||
|
},
|
||||||
|
[&](const AutoArgStdin & arg) {
|
||||||
|
v->mkString(readFile(STDIN_FILENO));
|
||||||
}
|
}
|
||||||
}, arg);
|
}, arg);
|
||||||
res.insert(state.symbols.create(name), v);
|
res.insert(state.symbols.create(name), v);
|
||||||
|
|
|
@ -29,8 +29,9 @@ private:
|
||||||
struct AutoArgExpr { std::string expr; };
|
struct AutoArgExpr { std::string expr; };
|
||||||
struct AutoArgString { std::string s; };
|
struct AutoArgString { std::string s; };
|
||||||
struct AutoArgFile { std::filesystem::path path; };
|
struct AutoArgFile { std::filesystem::path path; };
|
||||||
|
struct AutoArgStdin { };
|
||||||
|
|
||||||
using AutoArg = std::variant<AutoArgExpr, AutoArgString, AutoArgFile>;
|
using AutoArg = std::variant<AutoArgExpr, AutoArgString, AutoArgFile, AutoArgStdin>;
|
||||||
|
|
||||||
std::map<std::string, AutoArg> autoArgs;
|
std::map<std::string, AutoArg> autoArgs;
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,3 +49,6 @@ printf 123 > $TEST_ROOT/xyzzy/default.nix
|
||||||
if [[ -e /proc/version ]]; then
|
if [[ -e /proc/version ]]; then
|
||||||
[[ "$(nix eval --raw --arg-from-file foo /proc/version --expr '{ foo }: { inherit foo; }' foo)" = "$(cat /proc/version)" ]]
|
[[ "$(nix eval --raw --arg-from-file foo /proc/version --expr '{ foo }: { inherit foo; }' foo)" = "$(cat /proc/version)" ]]
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Test --arg-from-stdin.
|
||||||
|
[[ "$(echo bla | nix eval --raw --arg-from-stdin foo --expr '{ foo }: { inherit foo; }' foo)" = bla ]]
|
||||||
|
|
Loading…
Reference in a new issue