~yoctocell/flaskell

f921198b0a5f9b37dba788cab5df4b758f02a02f — yoctocell 1 year, 9 months ago 242ac34
Cli.hs: Disable stdin
1 files changed, 10 insertions(+), 5 deletions(-)

M src/Flaskell/Cli.hs
M src/Flaskell/Cli.hs => src/Flaskell/Cli.hs +10 -5
@@ 10,10 10,12 @@ import           Flaskell.Ui
import           Options.Applicative
import           System.Environment  (getArgs, getProgName)
import           System.Exit
import           System.IO           (getContents)
import           System.IO           (getContents, getLine)

-- | Type of input
data Input = FileInput FilePath | StdInput

-- | CLI options
data Options = Options
  { version :: Bool
  , input   :: Input }


@@ 40,22 42,25 @@ cliArgs = Options
          (long "version"
          <> short 'v'
          <> help "Print the version number")
          <*> (fileInput <|> stdInput)
          <*> fileInput
          -- <*> (fileInput <|> stdInput)

-- | Parse CLI arguments
parseCliArgs :: Options -> IO ()
parseCliArgs options = case options of
  (Options True _) -> putStrLn versionNumber
  (Options False (FileInput file)) -> do
    contents <- readFile file
    feedCards . getCards $ contents
    -- FIXME hGetLine closed handle erro
    -- FIXME hGetLine closed handle error
  (Options False (StdInput)) -> do
    putStrLn "stdin"
    contents <- getArgs
    putStrLn $ last contents
    -- contents <- getContents
    -- length contents `seq` return ()
    -- feedCards . getCards $ contents

-- Take contents of a file and return a list of Flashcard
-- | Take contents of a file and return a list of Flashcard
getCards :: String -> [Flashcard]
getCards contents =
  let hints = getHint <$> (lines contents)