aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-03 14:08:18 +0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-03 14:08:18 +0200
commit782c0bff45593e7116d9b17b7de71b7ee636a807 (patch)
treea7662d37c71696c46dc9cc4ee5730325a11ecacb
parentd3dcdfa00691cfe6f6a939fde218f1980d3cf73c (diff)
nix eval: Add a --raw flag
Similar to "jq -r", this prints the evaluation result (which must be a string value) unquoted.
-rw-r--r--src/nix/eval.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/nix/eval.cc b/src/nix/eval.cc
index eb2b13a2d..981cefa80 100644
--- a/src/nix/eval.cc
+++ b/src/nix/eval.cc
@@ -10,6 +10,13 @@ using namespace nix;
struct CmdEval : MixJSON, InstallablesCommand
{
+ bool raw = false;
+
+ CmdEval()
+ {
+ mkFlag(0, "raw", "print strings unquoted", &raw);
+ }
+
std::string name() override
{
return "eval";
@@ -22,13 +29,18 @@ struct CmdEval : MixJSON, InstallablesCommand
void run(ref<Store> store) override
{
+ if (raw && json)
+ throw UsageError("--raw and --json are mutually exclusive");
+
auto state = getEvalState();
auto jsonOut = json ? std::make_unique<JSONList>(std::cout) : nullptr;
for (auto & i : installables) {
auto v = i->toValue(*state);
- if (json) {
+ if (raw) {
+ std::cout << state->forceString(*v);
+ } else if (json) {
PathSet context;
auto jsonElem = jsonOut->placeholder();
printValueAsJSON(*state, true, *v, jsonElem, context);