diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libmain/Makefile.am | 1 | ||||
-rw-r--r-- | src/libmain/shared.cc | 3 | ||||
-rw-r--r-- | src/nix-env/help.txt | 2 | ||||
-rw-r--r-- | src/nix-env/main.cc | 33 |
4 files changed, 28 insertions, 11 deletions
diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am index a4969ff36777..6d70b0406acc 100644 --- a/src/libmain/Makefile.am +++ b/src/libmain/Makefile.am @@ -7,4 +7,5 @@ AM_CXXFLAGS = \ -DNIX_DATA_DIR=\"$(datadir)\" \ -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \ -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \ + -DNIX_VERSION=\"$(VERSION)\" \ -I.. -I../../externals/inst/include -I../libutil -I../libstore diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index e91ef2667824..32f4f81240bb 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -70,6 +70,9 @@ static void initAndRun(int argc, char * * argv) else if (arg == "--help") { printHelp(); return; + } else if (arg == "--version") { + cout << format("%1% (Nix) %2%") % programId % NIX_VERSION << endl; + return; } else if (arg == "--keep-failed" || arg == "-K") keepFailed = true; else remaining.push_back(arg); diff --git a/src/nix-env/help.txt b/src/nix-env/help.txt index 823f5213acf9..f1419cdf7ae3 100644 --- a/src/nix-env/help.txt +++ b/src/nix-env/help.txt @@ -21,7 +21,7 @@ name `*' may be used to indicate all derivations. Query types: --name: print derivation names (default) - --expr / -e: print derivation store expression + --expr: print derivation store expression --status / -s: print installed/present status Query sources: diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index a2e9b119aeff..0fd4ec63ae07 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -29,6 +29,7 @@ struct DrvInfo }; typedef map<Path, DrvInfo> DrvInfos; +typedef vector<DrvInfo> DrvInfoList; void printHelp() @@ -547,6 +548,12 @@ static void opUninstall(Globals & globals, } +static bool cmpDrvByName(const DrvInfo & a, const DrvInfo & b) +{ + return a.name < b.name; +} + + static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) { @@ -556,7 +563,7 @@ static void opQuery(Globals & globals, for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ++i) if (*i == "--name") query = qName; - else if (*i == "--expr" || *i == "-e") query = qDrvPath; + else if (*i == "--expr") query = qDrvPath; else if (*i == "--status" || *i == "-s") query = qStatus; else if (*i == "--installed") source = sInstalled; else if (*i == "--available" || *i == "-a") source = sAvailable; @@ -580,19 +587,25 @@ static void opQuery(Globals & globals, } if (opArgs.size() != 0) throw UsageError("no arguments expected"); + + /* Sort them by name. */ + DrvInfoList drvs2; + for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) + drvs2.push_back(i->second); + sort(drvs2.begin(), drvs2.end(), cmpDrvByName); /* Perform the specified query on the derivations. */ switch (query) { case qName: { - for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) - cout << format("%1%\n") % i->second.name; + for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) + cout << format("%1%\n") % i->name; break; } case qDrvPath: { - for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) - cout << format("%1%\n") % i->second.drvPath; + for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) + cout << format("%1%\n") % i->drvPath; break; } @@ -605,14 +618,14 @@ static void opQuery(Globals & globals, i != installed.end(); ++i) installedPaths.insert(i->second.outPath); - for (DrvInfos::iterator i = drvs.begin(); i != drvs.end(); ++i) { - Paths subs = querySubstitutes(i->second.drvPath); + for (DrvInfoList::iterator i = drvs2.begin(); i != drvs2.end(); ++i) { + Paths subs = querySubstitutes(i->drvPath); cout << format("%1%%2%%3% %4%\n") - % (installedPaths.find(i->second.outPath) + % (installedPaths.find(i->outPath) != installedPaths.end() ? 'I' : '-') - % (isValidPath(i->second.outPath) ? 'P' : '-') + % (isValidPath(i->outPath) ? 'P' : '-') % (subs.size() > 0 ? 'S' : '-') - % i->second.name; + % i->name; } break; } |