diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-02-19T15·30+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-02-19T15·30+0100 |
commit | c31836008e45460513188a3fbeda4416f9153a05 (patch) | |
tree | b062ecb0979116fbc4cc0db76cba8c03a453b140 /src/nix-instantiate | |
parent | e707a8a526698de2237e6ac89e2f1ce6dbc63269 (diff) |
nix-instantiate: Add a flag --expr / -E to read expressions from the command line
This is basically a shortcut for ‘echo 'expr...' | nix-instantiate -’. Also supported by nix-build and nix-shell.
Diffstat (limited to 'src/nix-instantiate')
-rw-r--r-- | src/nix-instantiate/nix-instantiate.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index e9f1284eb182..94172869883d 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -89,6 +89,7 @@ void run(Strings args) EvalState state; Strings files; bool readStdin = false; + bool fromArgs = false; bool findFile = false; bool evalOnly = false; bool parseOnly = false; @@ -104,6 +105,8 @@ void run(Strings args) if (arg == "-") readStdin = true; + else if (arg == "--expr" || arg == "-E") + fromArgs = true; else if (arg == "--eval-only") evalOnly = true; else if (arg == "--read-write-mode") @@ -162,11 +165,13 @@ void run(Strings args) Expr * e = parseStdin(state); processExpr(state, attrPaths, parseOnly, strict, autoArgs, evalOnly, xmlOutput, xmlOutputSourceLocation, e); - } else if (files.empty()) + } else if (files.empty() && !fromArgs) files.push_back("./default.nix"); foreach (Strings::iterator, i, files) { - Expr * e = state.parseExprFromFile(resolveExprPath(lookupFileArg(state, *i))); + Expr * e = fromArgs + ? state.parseExprFromString(*i, absPath(".")) + : state.parseExprFromFile(resolveExprPath(lookupFileArg(state, *i))); processExpr(state, attrPaths, parseOnly, strict, autoArgs, evalOnly, xmlOutput, xmlOutputSourceLocation, e); } |