matebeamter/src/Types/Configuration.hs

45 lines
1002 B
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Types.Configuration where
import qualified Data.Text as T
import Options.Applicative as O
import Data.YAML as Y
import GHC.Generics
data Configuration = Configuration
{ configApiHost :: T.Text
, configApiPort :: Word
, configApiUri :: T.Text
, configApiSecure :: Bool
, configListenPort :: Word
, configLocalesLocation :: T.Text
}
deriving (Generic, Show)
instance FromYAML Configuration where
parseYAML = withMap "Configuration" $ \m -> Configuration
<$> m .: "api_host"
<*> m .: "api_port"
<*> m .:? "api_uri" .!= ""
<*> m .:? "api_secure" .!= False
<*> m .: "listen_port"
<*> m .: "locales_location"
newtype Options = Options
{ optConfigLocation :: T.Text
}
deriving (Show)
options :: O.Parser Options
options = Options
<$> strOption
( long "configuration"
<> short 'c'
<> metavar "FILEPATH"
<> help "The location of the configuration YAML-file"
)