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 Data.Monoid ((<>))
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
import System.Directory (doesDirectoryExist, makeAbsolute)
|
||||||
|
import System.Exit (die)
|
||||||
import System.FilePath.Posix (dropTrailingPathSeparator, isValid)
|
import System.FilePath.Posix (dropTrailingPathSeparator, isValid)
|
||||||
|
|
||||||
data Arguments = Arguments {
|
data Arguments = Arguments {
|
||||||
|
@ -39,8 +41,11 @@ directory = eitherReader $ \path ->
|
||||||
else Left "This string doesn't represent a valid path"
|
else Left "This string doesn't represent a valid path"
|
||||||
|
|
||||||
configuration :: IO Arguments
|
configuration :: IO Arguments
|
||||||
configuration =
|
configuration = do
|
||||||
execParser $
|
inputArguments <- execParser $ info (arguments <**> helper) fullDesc
|
||||||
info (arguments <**> helper)
|
directoryExists <- doesDirectoryExist $ sourceDir inputArguments
|
||||||
( fullDesc
|
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