introduce special command

This commit is contained in:
Filip Gralinski 2018-01-09 07:58:18 +01:00 committed by Filip Gralinski
parent a2814f2d12
commit 11b43b3a2a
2 changed files with 13 additions and 10 deletions

View File

@ -14,6 +14,7 @@ module GEval.Core
MetricOrdering(..), MetricOrdering(..),
getMetricOrdering, getMetricOrdering,
MetricValue, MetricValue,
GEvalSpecialCommand(..),
GEvalSpecification(..), GEvalSpecification(..),
GEvalOptions(..), GEvalOptions(..),
GEvalException(..), GEvalException(..),
@ -144,8 +145,10 @@ getExpectedDirectory :: GEvalSpecification -> FilePath
getExpectedDirectory spec = fromMaybe outDirectory $ gesExpectedDirectory spec getExpectedDirectory spec = fromMaybe outDirectory $ gesExpectedDirectory spec
where outDirectory = gesOutDirectory spec where outDirectory = gesOutDirectory spec
data GEvalSpecialCommand = Init
data GEvalOptions = GEvalOptions data GEvalOptions = GEvalOptions
{ geoInit :: Bool, { geoSpecialCommand :: Maybe GEvalSpecialCommand,
geoPrecision :: Maybe Int, geoPrecision :: Maybe Int,
geoSpec :: GEvalSpecification } geoSpec :: GEvalSpecification }

View File

@ -26,9 +26,9 @@ fullOptionsParser = info (helper <*> optionsParser)
optionsParser :: Parser GEvalOptions optionsParser :: Parser GEvalOptions
optionsParser = GEvalOptions optionsParser = GEvalOptions
<$> switch <$> optional (flag' Init
( long "init" ( long "init"
<> help "Init a sample Gonito challenge rather than run an evaluation" ) <> help "Init a sample Gonito challenge rather than run an evaluation" ))
<*> optional precisionArgParser <*> optional precisionArgParser
<*> specParser <*> specParser
@ -127,15 +127,15 @@ attemptToReadOptsFromConfigFile args opts = do
runGEval'' :: GEvalOptions -> IO (Maybe MetricValue) runGEval'' :: GEvalOptions -> IO (Maybe MetricValue)
runGEval'' opts = runGEval''' (geoInit opts) (geoSpec opts) runGEval'' opts = runGEval''' (geoSpecialCommand opts) (geoSpec opts)
runGEval''' :: Bool -> GEvalSpecification -> IO (Maybe MetricValue) runGEval''' :: Maybe GEvalSpecialCommand -> GEvalSpecification -> IO (Maybe MetricValue)
runGEval''' True spec = do runGEval''' Nothing spec = do
initChallenge spec
return Nothing
runGEval''' False spec = do
val <- geval spec val <- geval spec
return $ Just val return $ Just val
runGEval''' (Just Init) spec = do
initChallenge spec
return Nothing
initChallenge :: GEvalSpecification -> IO () initChallenge :: GEvalSpecification -> IO ()
initChallenge spec = case gesExpectedDirectory spec of initChallenge spec = case gesExpectedDirectory spec of