mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
* `nix-instantiate --print-args' prints out the arguments of a
top-level function.
This commit is contained in:
parent
0e6dc72a7a
commit
2317d8f671
3 changed files with 28 additions and 7 deletions
|
@ -124,15 +124,15 @@ static void getDerivations(EvalState & state, Expr e,
|
||||||
DrvInfos & drvs, Exprs & doneExprs, const string & attrPath,
|
DrvInfos & drvs, Exprs & doneExprs, const string & attrPath,
|
||||||
const string & pathTaken)
|
const string & pathTaken)
|
||||||
{
|
{
|
||||||
/* Automatically call functions that have defaults for all
|
/* Automatically call functions for which each argument has a
|
||||||
arguments. */
|
default value. */
|
||||||
ATermList formals;
|
ATermList formals;
|
||||||
ATerm body, pos;
|
ATerm body, pos;
|
||||||
if (matchFunction(e, formals, body, pos)) {
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Expr name, def; ATerm values, def2;
|
Expr name, def; ATerm values, def2;
|
||||||
if (!matchFormal(*i, name, values, def2)) abort();
|
if (!matchFormal(*i, name, values, def2)) abort();
|
||||||
if (!matchDefaultValue(def2, def))
|
if (!matchDefaultValue(def2, def))
|
||||||
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
||||||
% aterm2String(name));
|
% aterm2String(name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,6 @@ Options:
|
||||||
--eval-only: evaluate and print resulting term; do not instantiate
|
--eval-only: evaluate and print resulting term; do not instantiate
|
||||||
--parse-only: parse and print abstract syntax tree
|
--parse-only: parse and print abstract syntax tree
|
||||||
|
|
||||||
|
--attr / -A PATH: select an attribute from the top-level expression
|
||||||
|
|
||||||
--add-root: add garbage collector roots for the result
|
--add-root: add garbage collector roots for the result
|
||||||
|
|
|
@ -33,11 +33,25 @@ static int rootNr = 0;
|
||||||
static bool indirectRoot = false;
|
static bool indirectRoot = false;
|
||||||
|
|
||||||
|
|
||||||
static void printResult(EvalState & state, Expr e, bool evalOnly,
|
static void printResult(EvalState & state, Expr e,
|
||||||
const string & attrPath)
|
bool evalOnly, bool printArgs, const string & attrPath)
|
||||||
{
|
{
|
||||||
if (evalOnly)
|
if (evalOnly)
|
||||||
cout << format("%1%\n") % e;
|
cout << format("%1%\n") % e;
|
||||||
|
|
||||||
|
else if (printArgs) {
|
||||||
|
ATermList formals;
|
||||||
|
ATerm body, pos;
|
||||||
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr name; ATerm d1, d2;
|
||||||
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
||||||
|
cout << format("%1%\n") % aterm2String(name);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
printMsg(lvlError, "warning: expression does not evaluate to a function");
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
DrvInfos drvs;
|
DrvInfos drvs;
|
||||||
getDerivations(state, e, drvs, attrPath);
|
getDerivations(state, e, drvs, attrPath);
|
||||||
|
@ -62,6 +76,7 @@ void run(Strings args)
|
||||||
bool readStdin = false;
|
bool readStdin = false;
|
||||||
bool evalOnly = false;
|
bool evalOnly = false;
|
||||||
bool parseOnly = false;
|
bool parseOnly = false;
|
||||||
|
bool printArgs = false;
|
||||||
string attrPath;
|
string attrPath;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin();
|
for (Strings::iterator i = args.begin();
|
||||||
|
@ -79,6 +94,10 @@ void run(Strings args)
|
||||||
readOnlyMode = true;
|
readOnlyMode = true;
|
||||||
parseOnly = evalOnly = true;
|
parseOnly = evalOnly = true;
|
||||||
}
|
}
|
||||||
|
else if (arg == "--print-args") {
|
||||||
|
readOnlyMode = true;
|
||||||
|
printArgs = true;
|
||||||
|
}
|
||||||
else if (arg == "--add-root") {
|
else if (arg == "--add-root") {
|
||||||
if (i == args.end())
|
if (i == args.end())
|
||||||
throw UsageError("`--add-root requires an argument");
|
throw UsageError("`--add-root requires an argument");
|
||||||
|
@ -101,7 +120,7 @@ void run(Strings args)
|
||||||
|
|
||||||
if (readStdin) {
|
if (readStdin) {
|
||||||
Expr e = evalStdin(state, parseOnly);
|
Expr e = evalStdin(state, parseOnly);
|
||||||
printResult(state, e, evalOnly, attrPath);
|
printResult(state, e, evalOnly, printArgs, attrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Strings::iterator i = files.begin();
|
for (Strings::iterator i = files.begin();
|
||||||
|
@ -111,7 +130,7 @@ void run(Strings args)
|
||||||
Expr e = parseOnly
|
Expr e = parseOnly
|
||||||
? parseExprFromFile(state, path)
|
? parseExprFromFile(state, path)
|
||||||
: evalFile(state, path);
|
: evalFile(state, path);
|
||||||
printResult(state, e, evalOnly, attrPath);
|
printResult(state, e, evalOnly, printArgs, attrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
printEvalStats(state);
|
printEvalStats(state);
|
||||||
|
|
Loading…
Reference in a new issue