From 10d767157c21b006e6de9de4566bc2d286fd391c Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Tue, 15 Oct 2019 23:11:07 +0300 Subject: [PATCH] Option parser --- koodihaaste.cabal | 1 + src/Main.hs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/koodihaaste.cabal b/koodihaaste.cabal index f1ccebe..cf54248 100644 --- a/koodihaaste.cabal +++ b/koodihaaste.cabal @@ -32,6 +32,7 @@ executable koodihaaste build-depends: base >=4.12 && <4.13 , servant , servant-server + , optparse-generic , servant-client , servant-client-core , text diff --git a/src/Main.hs b/src/Main.hs index 2dd331e..4c61ef0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,17 +1,28 @@ -{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeOperators #-} module Main where import Control.Monad.App import Data.Config +import Data.Language +import qualified Data.Text.IO as T import Network.HTTP.Client.TLS (newTlsManager) +import Options.Generic import Servant.Client import Server -import qualified Data.Text.IO as T -import Data.Language + +newtype Cmd = Cmd (FilePath "Config path") + deriving Generic + +instance ParseRecord Cmd main :: IO () main = do - _config <- readConfigFromFile "config.yaml" + Cmd (Helpful configPath) <- getRecord "koodihaaste" + _config <- readConfigFromFile configPath manager <- newTlsManager _languageModel <- buildModel <$> T.readFile (_training _config) let state = App{..}