32 lines
932 B
Haskell
32 lines
932 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Config where
|
|
|
|
import qualified Toml
|
|
import Toml(TomlCodec, (.=))
|
|
import qualified Data.Text as T
|
|
import Monad
|
|
|
|
data Config = Config {
|
|
mailDomain :: String
|
|
,mailUsername :: String
|
|
,mailPassword :: String
|
|
,mailTo :: T.Text
|
|
,mailFrom :: T.Text
|
|
,mailErrorTo :: T.Text
|
|
} deriving Show
|
|
|
|
configCodec :: TomlCodec Config
|
|
configCodec = flip Toml.table "mail" $ Config
|
|
<$> Toml.string "domain" .= mailDomain
|
|
<*> Toml.string "user" .= mailUsername
|
|
<*> Toml.string "password" .= mailPassword
|
|
<*> Toml.text "to" .= mailTo
|
|
<*> Toml.text "from" .= mailFrom
|
|
<*> Toml.text "errorTo" .= mailErrorTo
|
|
|
|
parseConfigFile :: (MonadIO m, MonadFail m) => String -> m Config
|
|
parseConfigFile path = do
|
|
config <- liftIO $ Toml.decodeFileEither configCodec path
|
|
case config of
|
|
Left errors -> fail $ unwords $ fmap show errors
|
|
Right x -> return x
|