about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-03-10T16·20+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-03-10T16·20+0000
commit37d1b1cafd17a18dc7dbef3b4ba7fb204158d58b (patch)
tree65ac3fdf078404a0957c5df5af855849e03be20f /src/libexpr/primops.cc
parenta33fb2d28738376d377ea8473f6cffc39bc784c4 (diff)
* `nix-env -qa --description' shows human-readable descriptions of
  packages (provided that they have a `meta.description' attribute).
  E.g.,

  $ ./src/nix-env/nix-env -qa --description gcc
  gcc-4.0.2   GNU Compiler Collection, 4.0.x (cross-compiler for sparc-linux)
  gcc-4.0.2   GNU Compiler Collection, 4.0.x (cross-compiler for mips-linux)
  gcc-4.0.2   GNU Compiler Collection, 4.0.x (cross-compiler for arm-linux)
  gcc-4.0.2   GNU Compiler Collection, 4.0.x


Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 77721a5a8d87..c5560be971df 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -390,14 +390,21 @@ static Expr primDirOf(EvalState & state, const ATermVector & args)
 }
 
 
+ATerm coerceToString(Expr e)
+{
+    ATerm s;
+    if (matchStr(e, s) || matchPath(e, s) || matchUri(e, s))
+        return s;
+    return 0;
+}
+
+
 /* Convert the argument (which can be a path or a uri) to a string. */
 static Expr primToString(EvalState & state, const ATermVector & args)
 {
-    Expr arg = evalExpr(state, args[0]);
-    ATerm s;
-    if (matchStr(arg, s) || matchPath(arg, s) || matchUri(arg, s))
-        return makeStr(s);
-    throw Error("cannot coerce value to string");
+    ATerm s = coerceToString(evalExpr(state, args[0]));
+    if (!s) throw Error("cannot coerce value to string");
+    return makeStr(s);
 }