diff options
Diffstat (limited to 'src/Config.hs')
-rw-r--r-- | src/Config.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Config.hs b/src/Config.hs new file mode 100644 index 0000000..c01bbe1 --- /dev/null +++ b/src/Config.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} + +module Config + ( getConfig + , Config(..) + ) where + +import Data.ConfigFile +import Data.Text (Text) +import qualified Data.Text as T + +import Control.Monad.Trans.Error (runErrorT) +import Control.Monad.IO.Class (liftIO) +import Control.Monad (join) +import Control.Arrow (left) +import Control.Applicative (liftA2) + +data Config = Config + { mailTo :: Text + , mailFrom :: Text + } deriving (Read, Eq, Show) + +getConfig :: FilePath -> IO (Either Text Config) +getConfig filePath = + left (T.pack . show) <$> (runErrorT $ do + cp <- join $ liftIO $ readfile emptyCP filePath + liftA2 + Config + (T.pack <$> get cp "DEFAULT" "mail-to") + (T.pack <$> get cp "DEFAULT" "mail-from") + ) |