module Dib.Util (
getSubDirectories,
handleExitCode
) where
import Dib.Types
import System.Exit (ExitCode(ExitSuccess, ExitFailure))
import Control.Monad
import qualified Data.Text as T
import qualified System.Directory as D
getSubDirectories :: FilePath -> IO [FilePath]
getSubDirectories root = do
contents <- D.getDirectoryContents root
let filteredDirs = filter (\x -> x /= "." && x /= "..") contents
dirs <- filterM (\(x, _) -> D.doesDirectoryExist x) $ zip (map (root ++) filteredDirs) filteredDirs
return $ map snd dirs
handleExitCode :: ExitCode -> T.Text -> String -> IO StageResult
handleExitCode ExitSuccess t _ = return $ Right $ OneToOne t ""
handleExitCode (ExitFailure _) _ e = return $ Left $ T.pack (show e)