about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-14T10·15+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-14T10·15+0200
commitd04e1ff12aef86e3653c6fb3e114c0bb58c5d255 (patch)
treea121d974396addccf813120bd4be9aba209250b7 /src/nix-store
parent2c1711ae33c0824570dab4651c5aefd273e8eba6 (diff)
nix-store -q: Check for conflicting flags
Fixes #364.
Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/nix-store.cc16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 51839fac11ee..c91bca97d534 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -265,15 +265,18 @@ static void printTree(const Path & path,
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qOutputs, qRequisites, qReferences, qReferrers
-         , qReferrersClosure, qDeriver, qBinding, qHash, qSize
-         , qTree, qGraph, qXml, qResolve, qRoots } query = qOutputs;
+    enum QueryType
+        { qDefault, qOutputs, qRequisites, qReferences, qReferrers
+        , qReferrersClosure, qDeriver, qBinding, qHash, qSize
+        , qTree, qGraph, qXml, qResolve, qRoots };
+    QueryType query = qDefault;
     bool useOutput = false;
     bool includeOutputs = false;
     bool forceRealise = false;
     string bindingName;
 
-    foreach (Strings::iterator, i, opFlags)
+    foreach (Strings::iterator, i, opFlags) {
+        QueryType prev = query;
         if (*i == "--outputs") query = qOutputs;
         else if (*i == "--requisites" || *i == "-R") query = qRequisites;
         else if (*i == "--references") query = qReferences;
@@ -298,6 +301,11 @@ static void opQuery(Strings opFlags, Strings opArgs)
         else if (*i == "--force-realise" || *i == "--force-realize" || *i == "-f") forceRealise = true;
         else if (*i == "--include-outputs") includeOutputs = true;
         else throw UsageError(format("unknown flag ‘%1%’") % *i);
+        if (prev != qDefault && prev != query)
+            throw UsageError(format("query type ‘%1%’ conflicts with earlier flag") % *i);
+    }
+
+    if (query == qDefault) query = qOutputs;
 
     RunPager pager;