From 228b7b06060090856d2ecd605009a6f270139ac8 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 22 Aug 2015 19:44:46 +0200 Subject: [PATCH] move option parsing to lib --- app/Main.hs | 53 +--------------------------------------- geval.cabal | 6 +++-- src/OptionsParser.hs | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 src/OptionsParser.hs diff --git a/app/Main.hs b/app/Main.hs index 32584dc..da8c516 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 diff --git a/geval.cabal b/geval.cabal index 38b1450..e8987ff 100644 --- a/geval.cabal +++ b/geval.cabal @@ -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 diff --git a/src/OptionsParser.hs b/src/OptionsParser.hs new file mode 100644 index 0000000..135b385 --- /dev/null +++ b/src/OptionsParser.hs @@ -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" )