From d04e1ff12aef86e3653c6fb3e114c0bb58c5d255 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Oct 2014 12:15:39 +0200 Subject: [PATCH] nix-store -q: Check for conflicting flags Fixes #364. --- src/nix-store/nix-store.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 51839fac1..c91bca97d 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;