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 = 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 ()

View File

@ -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