From d9f30fe7c74ae8518a575c0d15ee00aa46a2229a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 2 Feb 2004 10:51:54 +0000 Subject: [PATCH] * Sort `nix-env -q' output by derivation name. * `--version' flag for all commands. * Manual updates. --- doc/manual/Makefile.am | 2 +- doc/manual/manual.xml | 3 +- doc/manual/nix-env.xml | 9 ++--- doc/manual/nix-instantiate.xml | 22 +++--------- doc/manual/nix-store.xml | 21 ++--------- doc/manual/opt-common-syn.xml | 8 +++++ .../{opt-verbose.xml => opt-common.xml} | 35 +++++++++++++++++++ src/libmain/Makefile.am | 1 + src/libmain/shared.cc | 3 ++ src/nix-env/help.txt | 2 +- src/nix-env/main.cc | 33 +++++++++++------ 11 files changed, 83 insertions(+), 56 deletions(-) create mode 100644 doc/manual/opt-common-syn.xml rename doc/manual/{opt-verbose.xml => opt-common.xml} (76%) diff --git a/doc/manual/Makefile.am b/doc/manual/Makefile.am index b1f5c3f46..8bf06cf2b 100644 --- a/doc/manual/Makefile.am +++ b/doc/manual/Makefile.am @@ -8,7 +8,7 @@ XSLTPROC = $(ENV) $(xsltproc) $(xmlflags) --catalogs \ SOURCES = manual.xml introduction.xml installation.xml overview.xml \ nix-env.xml nix-store.xml nix-instantiate.xml \ - troubleshooting.xml bugs.xml opt-verbose.xml \ + troubleshooting.xml bugs.xml opt-common.xml opt-common-syn.xml \ quick-start.xml style.css images manual.is-valid: $(SOURCES) version.xml diff --git a/doc/manual/manual.xml b/doc/manual/manual.xml index d47e57123..686ab612f 100644 --- a/doc/manual/manual.xml +++ b/doc/manual/manual.xml @@ -7,7 +7,8 @@ - + + diff --git a/doc/manual/nix-env.xml b/doc/manual/nix-env.xml index c73716381..a943fd976 100644 --- a/doc/manual/nix-env.xml +++ b/doc/manual/nix-env.xml @@ -7,12 +7,7 @@ nix-env - - - - - - + &opt-common-syn; @@ -71,7 +66,7 @@ - &opt-verbose; + &opt-common; / diff --git a/doc/manual/nix-instantiate.xml b/doc/manual/nix-instantiate.xml index 2e2749e43..ee073a17b 100644 --- a/doc/manual/nix-instantiate.xml +++ b/doc/manual/nix-instantiate.xml @@ -1,16 +1,13 @@ nix-instantiate - generate Nix expressions from a high-level description + instantiate store expressions from Nix expressions - fix - - - - + nix-instantiate + &opt-common-syn; files @@ -19,19 +16,10 @@ Description - The command fix generates Nix expressions from - expressions is Fix's own high-level language. While Nix expressions are - very primitive and not intended to be written directly, Fix expressions - are quite easy to write. + The command nix-instantiate generates + (low-level) store expressions from (high-level) Nix expressions. - - - diff --git a/doc/manual/nix-store.xml b/doc/manual/nix-store.xml index 7758d04ea..a3fcad063 100644 --- a/doc/manual/nix-store.xml +++ b/doc/manual/nix-store.xml @@ -7,12 +7,7 @@ nix-store - - - - - - + &opt-common-syn; operation options arguments @@ -51,19 +46,7 @@ - &opt-verbose; - - - / - - - Specifies that in case of a build failure, the temporary directory - (usually in /tmp) in which the build takes - place should not be deleted. The path of the build directory is - printed as an informational message. - - - + &opt-common; diff --git a/doc/manual/opt-common-syn.xml b/doc/manual/opt-common-syn.xml new file mode 100644 index 000000000..3a3e4ce87 --- /dev/null +++ b/doc/manual/opt-common-syn.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/doc/manual/opt-verbose.xml b/doc/manual/opt-common.xml similarity index 76% rename from doc/manual/opt-verbose.xml rename to doc/manual/opt-common.xml index 53fe07ae7..6c8db2a72 100644 --- a/doc/manual/opt-verbose.xml +++ b/doc/manual/opt-common.xml @@ -1,3 +1,23 @@ + + + + + Prints out a summary of the command syntax and exits. + + + + + + + + + + Prints out the Nix version number on standard output and exits. + + + + + / @@ -72,6 +92,7 @@ + / @@ -85,3 +106,17 @@ + + + + / + + + Specifies that in case of a build failure, the temporary + directory (usually in /tmp) in which the + build takes place should not be deleted. The path of the build + directory is printed as an informational message. + + + + diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am index a4969ff36..6d70b0406 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 e91ef2667..32f4f8124 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 823f5213a..f1419cdf7 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 a2e9b119a..0fd4ec63a 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -29,6 +29,7 @@ struct DrvInfo }; typedef map DrvInfos; +typedef vector 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; }