mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
* `nix-instantiate --print-args': print out the valid values for
functions arguments that have a domain.
This commit is contained in:
parent
ca2238cf81
commit
c11839d7b2
3 changed files with 37 additions and 3 deletions
|
@ -308,3 +308,27 @@ string showType(Expr e)
|
||||||
return "an unknown type";
|
return "an unknown type";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string showValue(Expr e)
|
||||||
|
{
|
||||||
|
ATerm s;
|
||||||
|
int i;
|
||||||
|
if (matchStr(e, s)) {
|
||||||
|
string t = aterm2String(s), u;
|
||||||
|
for (string::iterator i = t.begin(); i != t.end(); ++i)
|
||||||
|
if (*i == '\"' || *i == '\\') u += "\\" + *i;
|
||||||
|
else if (*i == '\n') u += "\\n";
|
||||||
|
else if (*i == '\r') u += "\\r";
|
||||||
|
else if (*i == '\t') u += "\\t";
|
||||||
|
else u += *i;
|
||||||
|
return "\"" + u + "\"";
|
||||||
|
}
|
||||||
|
if (matchPath(e, s)) return aterm2String(s);
|
||||||
|
if (matchUri(e, s)) return aterm2String(s);
|
||||||
|
if (matchNull(e)) return "null";
|
||||||
|
if (matchInt(e, i)) return (format("%1%") % i).str();
|
||||||
|
if (e == eTrue) return "true";
|
||||||
|
if (e == eFalse) return "false";
|
||||||
|
/* !!! incomplete */
|
||||||
|
return "<unknown>";
|
||||||
|
}
|
||||||
|
|
|
@ -92,5 +92,7 @@ Expr makeBool(bool b);
|
||||||
|
|
||||||
string showType(Expr e);
|
string showType(Expr e);
|
||||||
|
|
||||||
|
string showValue(Expr e);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__NIXEXPR_H */
|
#endif /* !__NIXEXPR_H */
|
||||||
|
|
|
@ -44,9 +44,17 @@ static void printResult(EvalState & state, Expr e,
|
||||||
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; ATerm d1, d2;
|
Expr name; ValidValues valids; ATerm dummy;
|
||||||
if (!matchFormal(*i, name, d1, d2)) abort();
|
if (!matchFormal(*i, name, valids, dummy)) abort();
|
||||||
cout << format("%1%\n") % aterm2String(name);
|
cout << format("%1%: ") % aterm2String(name);
|
||||||
|
ATermList valids2;
|
||||||
|
if (matchValidValues(valids, valids2)) {
|
||||||
|
for (ATermIterator j(valids2); j; ++j) {
|
||||||
|
Expr e = evalExpr(state, *j);
|
||||||
|
cout << format("%1% ") % showValue(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << format("\n");
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
printMsg(lvlError, "warning: expression does not evaluate to a function");
|
printMsg(lvlError, "warning: expression does not evaluate to a function");
|
||||||
|
|
Loading…
Reference in a new issue