move main run procedure to OptionsParser

This commit is contained in:
Filip Gralinski 2015-08-22 20:28:10 +02:00 committed by Filip Gralinski
parent 228b7b0606
commit 4efd99bef9
2 changed files with 17 additions and 4 deletions

View File

@ -8,6 +8,9 @@ import OptionsParser
main :: IO () main :: IO ()
main = do main = do
opts <- execParser fullOptionsParser args <- getArgs
result <- geval $ geoSpec opts result <- runGEval args
print $ result case result of
Left parseResult -> handleParseResult parseResult >> return ()
Right (Just result) -> print $ result
Right Nothing -> return ()

View File

@ -1,5 +1,6 @@
module OptionsParser module OptionsParser
(fullOptionsParser) where (fullOptionsParser,
runGEval) where
import Options.Applicative import Options.Applicative
import GEval import GEval
@ -55,3 +56,12 @@ metricReader = option auto
<> showDefault <> showDefault
<> metavar "METRIC" <> metavar "METRIC"
<> help "Metric to be used" ) <> help "Metric to be used" )
runGEval :: [String] -> IO (Either (ParserResult GEvalOptions) (Maybe Double))
runGEval args =
case parserResult of
Success opts -> do
val <- geval $ geoSpec opts
return $ Right $ Just val
otherwise -> return $ Left parserResult
where parserResult = execParserPure (prefs idm) fullOptionsParser args