Make input directory absolute and check it exists

This commit is contained in:
Tissevert 2019-02-02 15:22:59 +01:00
parent 62055a6a54
commit a9f220f9d8

View file

@ -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"