From f803f8fb22197ac242af61969c9183e040f3ec62 Mon Sep 17 00:00:00 2001 From: Armando Ramirez Date: Wed, 3 Apr 2024 10:28:30 -0700 Subject: [PATCH] graphex graph all fails when no modules match the query (#59) --- ChangeLog.md | 2 ++ app/Main.hs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 9254ddf..2409a06 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,8 @@ ## Unreleased changes +- `graphex graph all` now fails when no modules match the query. + ## 0.1.2.1 - Fix `graphex cabal` for units with multiple source directories. diff --git a/app/Main.hs b/app/Main.hs index 5f653ae..40ee759 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,7 @@ {-# LANGUAGE ApplicativeDo #-} module Main where +import Control.Monad (when) import Data.Aeson (encode) import Data.Bool (bool) import qualified Data.ByteString.Lazy as BL @@ -8,6 +9,7 @@ import qualified Data.Csv as CSV import Data.Foldable import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE +import qualified Data.Map as Map import Data.Maybe (fromMaybe) import Data.Text (Text) import qualified Data.Text as T @@ -137,7 +139,8 @@ main = customExecParser (prefs showHelpOnError) opts >>= \case AllDepsOn{..} -> do let ms = if | useRegex -> filter (\m -> any (m =~) patterns) (graphNodes graph) - | otherwise -> NE.toList patterns + | otherwise -> filter (flip Map.member (unGraph graph)) $ NE.toList patterns + when (null ms) $ error $ unwords ["No nodes in the graph match:", show patterns] printStrs $ foldMap (allDepsOn graph) ms Rankings -> printStrs $ fmap (\(n,m) -> m <> " - " <> (T.pack . show) n) $ rankings graph FindLongest -> printStrs $ longest graph