From df648c4967af7298fe55f75c7616e39e5b5e7d37 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 22 Jul 2003 10:24:22 +0000 Subject: [PATCH] * `nix --query --expansion' (`-qe') to get any path with content corresponding to the given id. --- src/nix.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/nix.cc b/src/nix.cc index f8e019eb4..e08854227 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(); }