move option parsing to lib

This commit is contained in:
Filip Gralinski 2015-08-22 19:44:46 +02:00 committed by Filip Gralinski
parent 866917fc3f
commit 228b7b0606
3 changed files with 62 additions and 54 deletions

View File

@ -4,58 +4,7 @@ import GEval
import System.Environment
import Options.Applicative
fullOptionsParser = info (helper <*> optionsParser)
(fullDesc
<> progDesc "Run evaluation for tests in Gonito platform"
<> header "geval - stand-alone evaluation tool for tests in Gonito platform")
optionsParser :: Parser GEvalOptions
optionsParser = GEvalOptions
<$> switch
( long "init"
<> help "Init a sample Gonito challange rather than run an evaluation" )
<*> specParser
specParser :: Parser GEvalSpecification
specParser = GEvalSpecification
<$> strOption
( long "out-directory"
<> value defaultOutDirectory
<> showDefault
<> metavar "OUT-DIRECTORY"
<> help "Directory with test results to be evaluated" )
<*> optional (strOption
( long "expected-directory"
<> metavar "EXPECTED-DIRECTORY"
<> help "Directory with expected test results (if not specified the same as OUT-DIRECTORY)" ))
<*> strOption
( long "test-name"
<> value defaultTestName
<> showDefault
<> metavar "NAME"
<> help "Test name (i.e. subdirectory with results or expected results)" )
<*> strOption
( long "out-file"
<> value defaultOutFile
<> showDefault
<> metavar "OUT"
<> help "The name of the file to be evaluated" )
<*> strOption
( long "expected-file"
<> value defaultExpectedFile
<> showDefault
<> metavar "EXPECTED"
<> help "The name of the file with expected results" )
<*> metricReader
metricReader :: Parser Metric
metricReader = option auto
( long "metric"
<> value defaultMetric
<> showDefault
<> metavar "METRIC"
<> help "Metric to be used" )
import OptionsParser
main :: IO ()
main = do

View File

@ -5,8 +5,8 @@ description: Please see README.md
homepage: http://github.com/name/project
license: Apache
license-file: LICENSE
author: Your name here
maintainer: your.address@example.com
author: Filip Gralinski
maintainer: filipg@amu.edu.pl
-- copyright:
category: Web
build-type: Simple
@ -16,6 +16,7 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: GEval
, OptionsParser
build-depends: base >= 4.7 && < 5
, cond
, conduit
@ -23,6 +24,7 @@ library
, conduit-extra
, directory
, filepath
, optparse-applicative
, resourcet
, text
default-language: Haskell2010

57
src/OptionsParser.hs Normal file
View File

@ -0,0 +1,57 @@
module OptionsParser
(fullOptionsParser) where
import Options.Applicative
import GEval
fullOptionsParser = info (helper <*> optionsParser)
(fullDesc
<> progDesc "Run evaluation for tests in Gonito platform"
<> header "geval - stand-alone evaluation tool for tests in Gonito platform")
optionsParser :: Parser GEvalOptions
optionsParser = GEvalOptions
<$> switch
( long "init"
<> help "Init a sample Gonito challange rather than run an evaluation" )
<*> specParser
specParser :: Parser GEvalSpecification
specParser = GEvalSpecification
<$> strOption
( long "out-directory"
<> value defaultOutDirectory
<> showDefault
<> metavar "OUT-DIRECTORY"
<> help "Directory with test results to be evaluated" )
<*> optional (strOption
( long "expected-directory"
<> metavar "EXPECTED-DIRECTORY"
<> help "Directory with expected test results (if not specified the same as OUT-DIRECTORY)" ))
<*> strOption
( long "test-name"
<> value defaultTestName
<> showDefault
<> metavar "NAME"
<> help "Test name (i.e. subdirectory with results or expected results)" )
<*> strOption
( long "out-file"
<> value defaultOutFile
<> showDefault
<> metavar "OUT"
<> help "The name of the file to be evaluated" )
<*> strOption
( long "expected-file"
<> value defaultExpectedFile
<> showDefault
<> metavar "EXPECTED"
<> help "The name of the file with expected results" )
<*> metricReader
metricReader :: Parser Metric
metricReader = option auto
( long "metric"
<> value defaultMetric
<> showDefault
<> metavar "METRIC"
<> help "Metric to be used" )