From 3f8d761d8ed9a4641d61439711353592cc4a1211 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Wed, 17 Jan 2018 22:27:14 +0000 Subject: [PATCH] Read filename from commandline argument --- app/Main.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 8d1aa23..40f6917 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -13,11 +13,17 @@ import qualified Data.ByteString.Lazy.Char8 as B import Lib data CmdLnOptions = CmdLnOptions - { optionIterations :: Integer + { optionFilename :: String + , optionIterations :: Integer , optionColor :: Color , optionWhiteBg :: Bool } +filenameParser :: Parser String +filenameParser = strArgument + (metavar "FILENAME" + <> help "JSON file specifying an L-system") + iterationsParser :: Parser Integer iterationsParser = option auto (long "iterations" @@ -58,7 +64,7 @@ whiteBackgroundParser = switch optionsParser :: Parser CmdLnOptions optionsParser = CmdLnOptions <$> - iterationsParser <*> colorParser <*> whiteBackgroundParser + filenameParser <*> iterationsParser <*> colorParser <*> whiteBackgroundParser opts :: ParserInfo CmdLnOptions opts = info (optionsParser <**> helper) @@ -73,7 +79,7 @@ createDisplay fgColor wbg n ls = display (InWindow (name ls) (200, 200) (10, 10) main :: IO () main = do - lsStr <- B.getContents + CmdLnOptions f n fgColor wbg <- execParser opts + lsStr <- B.readFile f let Just ls = decode lsStr :: Maybe (LSystem Char) - CmdLnOptions n fgColor wbg <- execParser opts createDisplay fgColor wbg n ls