From a9f220f9d83ac63269747ba6b26a4b92e9710191 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 2 Feb 2019 15:22:59 +0100 Subject: [PATCH] Make input directory absolute and check it exists --- src/Arguments.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Arguments.hs b/src/Arguments.hs index 8062483..2b2e900 100644 --- a/src/Arguments.hs +++ b/src/Arguments.hs @@ -6,6 +6,8 @@ module Arguments ( import Data.Monoid ((<>)) import Options.Applicative +import System.Directory (doesDirectoryExist, makeAbsolute) +import System.Exit (die) import System.FilePath.Posix (dropTrailingPathSeparator, isValid) data Arguments = Arguments { @@ -39,8 +41,11 @@ directory = eitherReader $ \path -> else Left "This string doesn't represent a valid path" configuration :: IO Arguments -configuration = - execParser $ - info (arguments <**> helper) - ( fullDesc - ) +configuration = do + inputArguments <- execParser $ info (arguments <**> helper) fullDesc + directoryExists <- doesDirectoryExist $ sourceDir inputArguments + if directoryExists + then do + absolutePath <- makeAbsolute $ sourceDir inputArguments + return $ inputArguments { sourceDir = absolutePath } + else die "INPUT_DIR doesn't exist"