mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 16:23:02 +00:00
* nix --query --expansion' (
-qe') to get any path with content
corresponding to the given id.
This commit is contained in:
parent
d84931ee56
commit
df648c4967
16
src/nix.cc
16
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user