about summary refs log tree commit diff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-store/nix-store.cc')
-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;