Make input directory absolute and check it exists
This commit is contained in:
parent
62055a6a54
commit
a9f220f9d8
1 changed files with 10 additions and 5 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue