From 4efd99bef9a6ddbb3809097929a0b41d179a8be6 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 22 Aug 2015 20:28:10 +0200 Subject: [PATCH] move main run procedure to OptionsParser --- app/Main.hs | 9 ++++++--- src/OptionsParser.hs | 12 +++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index da8c516..e434705 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -8,6 +8,9 @@ import OptionsParser main :: IO () main = do - opts <- execParser fullOptionsParser - result <- geval $ geoSpec opts - print $ result + args <- getArgs + result <- runGEval args + case result of + Left parseResult -> handleParseResult parseResult >> return () + Right (Just result) -> print $ result + Right Nothing -> return () diff --git a/src/OptionsParser.hs b/src/OptionsParser.hs index 135b385..8fe6e43 100644 --- a/src/OptionsParser.hs +++ b/src/OptionsParser.hs @@ -1,5 +1,6 @@ module OptionsParser - (fullOptionsParser) where + (fullOptionsParser, + runGEval) where import Options.Applicative import GEval @@ -55,3 +56,12 @@ metricReader = option auto <> showDefault <> metavar "METRIC" <> 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