Refactor helper function (for Gonito)

This commit is contained in:
Filip Gralinski 2020-09-28 21:24:14 +02:00
parent 5bd2eee13e
commit 4e033b8adb
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,5 @@
name: geval name: geval
version: 1.37.0.0 version: 1.37.1.0
synopsis: Machine learning evaluation tools synopsis: Machine learning evaluation tools
description: Please see README.md description: Please see README.md
homepage: http://github.com/name/project homepage: http://github.com/name/project

View File

@ -347,18 +347,21 @@ getOptions' readOptsFromConfigFile args =
otherwise -> return $ Left parserResult otherwise -> return $ Left parserResult
where parserResult = execParserPure (prefs idm) fullOptionsParser args where parserResult = execParserPure (prefs idm) fullOptionsParser args
readOptsFromConfigFile :: [String] -> FilePath -> IO (Either (ParserResult GEvalOptions) GEvalOptions)
readOptsFromConfigFile args configFilePath = do
configH <- openFile configFilePath ReadMode
contents <- hGetContents configH
getOptions' False ((words contents) ++ args)
attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) GEvalOptions) attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) GEvalOptions)
attemptToReadOptsFromConfigFile args opts = do attemptToReadOptsFromConfigFile args opts = do
configExists <- D.doesFileExist configFilePath configExists <- D.doesFileExist configFilePath
if configExists then do if configExists then do
configH <- openFile configFilePath ReadMode readOptsFromConfigFile args configFilePath
contents <- hGetContents configH
getOptions' False ((words contents) ++ args)
else else
getOptions' False args getOptions' False args
where configFilePath = (getExpectedDirectory $ geoSpec opts) </> configFileName where configFilePath = (getExpectedDirectory $ geoSpec opts) </> configFileName
runGEval'' :: GEvalOptions -> IO (Maybe [(SourceSpec, [MetricResult])]) runGEval'' :: GEvalOptions -> IO (Maybe [(SourceSpec, [MetricResult])])
runGEval'' opts = runGEval''' (geoSpecialCommand opts) runGEval'' opts = runGEval''' (geoSpecialCommand opts)
(geoResultOrdering opts) (geoResultOrdering opts)