~yoctocell/flaskell

f718e4e5d024ab5d36035e17305d6aa21004ecf2 — yoctocell 1 year, 9 months ago acdefda
Cli.hs: Add function to handle error
1 files changed, 9 insertions(+), 3 deletions(-)

M src/Flaskell/Cli.hs
M src/Flaskell/Cli.hs => src/Flaskell/Cli.hs +9 -3
@@ 1,6 1,5 @@
module Flaskell.Cli
  ( cli
  -- ( getContent
  )
where



@@ 14,7 13,7 @@ import           Options.Applicative
import           System.Environment             ( getArgs
                                                , getProgName
                                                )
import           System.Exit
import           System.Exit                    ( exitFailure )
import           System.IO                      ( getContents
                                                , getLine
                                                )


@@ 51,7 50,9 @@ parseCliArgs options = case options of
  (Options False (FileInput file)) -> do
    contents <- readFile file
    -- print $ getCards contents
    feedCards . getCards $ contents
    let result = getCards contents
    if result == [] then handleError else feedCards result
    -- feedCards . getCards $ contents
    -- FIXME hGetLine closed handle error
  (Options False (StdInput)) -> do
    contents <- getArgs


@@ 68,6 69,11 @@ getCards contents =
        Left  _   -> []
        Right res -> res

handleError :: IO ()
handleError = do
  putStrLn "Check the format of your file."
  exitFailure

cli :: IO ()
cli = do
  parseCliArgs =<< execParser args