never executed always true always false
    1 module CommandLine.ResolveFiles (resolveElmFiles, Error(..)) where
    2 
    3 -- This module provides reusable functions to resolve command line arguments into a list of Elm files
    4 
    5 import Prelude ()
    6 import Relude
    7 
    8 import CommandLine.InfoFormatter (ToConsole(..))
    9 import qualified CommandLine.Filesystem as Filesystem
   10 import CommandLine.World (World, FileType(..))
   11 import qualified CommandLine.World as World
   12 import Data.Either.Extra (collectErrors)
   13 import qualified Data.Text as Text
   14 
   15 
   16 data Error
   17     = FileDoesNotExist FilePath
   18     | NoElmFiles FilePath
   19 
   20 
   21 instance ToConsole Error where
   22     toConsole = \case
   23         FileDoesNotExist path -> Text.pack path <> ": No such file or directory"
   24         NoElmFiles path -> Text.pack path <> ": Directory does not contain any *.elm files"
   25 
   26 
   27 resolveFile :: World m => FilePath -> m (Either Error [FilePath])
   28 resolveFile path =
   29     do
   30         fileType <- World.stat path
   31 
   32         case fileType of
   33             IsFile ->
   34                 return $ Right [path]
   35 
   36             IsDirectory ->
   37                 do
   38                     elmFiles <- Filesystem.findAllElmFiles path
   39                     case elmFiles of
   40                         [] -> return $ Left $ NoElmFiles path
   41                         _ -> return $ Right elmFiles
   42 
   43             DoesNotExist ->
   44                 return $ Left $ FileDoesNotExist path
   45 
   46 
   47 resolveElmFiles :: World m => [FilePath] -> m (Either [Error] [FilePath])
   48 resolveElmFiles inputFiles =
   49     do
   50         result <- collectErrors <$> mapM resolveFile inputFiles
   51         case result of
   52             Left ls ->
   53                 return $ Left ls
   54 
   55             Right files ->
   56                 return $ Right $ concat files