From a7d45ea330a884ae445ca1ebdfa59f4f4f90eecc Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 22 Jun 2020 23:08:40 +0200 Subject: [PATCH] Fixup, dont show setup by default --- src-exe/cabal-plan.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src-exe/cabal-plan.hs b/src-exe/cabal-plan.hs index a163e7c..7fb3472 100644 --- a/src-exe/cabal-plan.hs +++ b/src-exe/cabal-plan.hs @@ -147,13 +147,13 @@ parsePattern = either (Left . show) Right . P.runParser (patternP <* P.eof) () " toCompType t = fail $ "Unknown component type: " ++ show t prettyPattern :: Pattern -> T.Text -prettyPattern (Pattern pkg kind cname) = - maybe "" (<> ":") pkg +prettyPattern (Pattern pkg kind cname) = + maybe "" (<> ":") pkg <> maybe "" ((<> ":") . prettyCompType) kind - <> fromMaybe "" cname + <> fromMaybe "" cname prettyCompType :: CompType -> T.Text -prettyCompType compType = case compType of +prettyCompType compType = case compType of CompTypeBench -> "bench" CompTypeExe -> "exe" CompTypeLib -> "lib" @@ -331,18 +331,24 @@ main = do depId <- findUniqueUnitOrExit plan depPat doWhyDepends optsUseColors plan compId depId where - findUniqueUnitOrExit :: PlanJson -> Pattern -> IO UnitId - findUniqueUnitOrExit p pat = - case findUnit p pat of + findUniqueUnitOrExit :: PlanJson -> Pattern -> IO UnitId + findUniqueUnitOrExit p pat = + case findUnit p pat of [(_, uid, _)] -> pure uid - [] -> do + [] -> do hPutStrLn stderr $ "Could not find any unit with pattern: " ++ T.unpack (prettyPattern pat) exitFailure - xs -> do + xs + | [(_, uid, _)] <- filter nonSetupUnits xs -> pure uid + | otherwise -> do hPutStrLn stderr $ "Ambiguous target \"" ++ T.unpack (prettyPattern pat) ++ "\". Found the following targets:" for_ xs $ \(t, _, _) -> hPutStrLn stderr $ " " ++ T.unpack t exitFailure + nonSetupUnits :: (Text, UnitId, CompName) -> Bool + nonSetupUnits (_, _, CompNameSetup) = False + nonSetupUnits _ = True + findPlan search = do cwd <- getCurrentDirectory (searchMethod, mProjRoot) <- case search of