about summary refs log tree commit diff
path: root/src/nix.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-22T10·24+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-22T10·24+0000
commitdf648c4967af7298fe55f75c7616e39e5b5e7d37 (patch)
treeeb39be3f0d814ee7410acf9ffb4b5490d8c40900 /src/nix.cc
parentd84931ee5607c152b4bc7eb23b7ab94ded9f85c7 (diff)
* `nix --query --expansion' (`-qe') to get any path with content
  corresponding to the given id.

Diffstat (limited to 'src/nix.cc')
-rw-r--r--src/nix.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/nix.cc b/src/nix.cc
index f8e019eb4a2f..e0885422762f 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -106,18 +106,19 @@ static void opAdd(Strings opFlags, Strings opArgs)
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qPaths, qRefs, qGenerators, qUnknown } query = qPaths;
+    enum { qList, qRefs, qGenerators, qExpansion } query = qList;
 
     for (Strings::iterator i = opFlags.begin();
          i != opFlags.end(); i++)
-        if (*i == "--list" || *i == "-l") query = qPaths;
+        if (*i == "--list" || *i == "-l") query = qList;
         else if (*i == "--refs" || *i == "-r") query = qRefs;
         else if (*i == "--generators" || *i == "-g") query = qGenerators;
+        else if (*i == "--expansion" || *i == "-e") query = qExpansion;
         else throw UsageError(format("unknown flag `%1%'") % *i);
 
     switch (query) {
         
-        case qPaths: {
+        case qList: {
             StringSet paths;
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
@@ -159,6 +160,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
             break;
         }
 
+        case qExpansion: {
+            for (Strings::iterator i = opArgs.begin();
+                 i != opArgs.end(); i++)
+                /* !!! should not use substitutes; this is a query,
+                   it should not have side-effects */
+                cout << format("%s\n") % expandId(parseHash(*i));
+            break;
+        }
+
         default:
             abort();
     }