aboutsummaryrefslogtreecommitdiff
path: root/src/Conf.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Conf.hs')
-rw-r--r--src/Conf.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Conf.hs b/src/Conf.hs
new file mode 100644
index 0000000..fccf2a5
--- /dev/null
+++ b/src/Conf.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Conf
+ ( parse
+ , Conf(..)
+ ) where
+
+import Data.Text (Text)
+import qualified Data.ConfigManager as Conf
+import Data.Time.Clock (NominalDiffTime)
+
+import Model.URL
+
+data Conf = Conf
+ { url :: URL
+ , mailFrom :: Text
+ , mailTo :: [Text]
+ , properties :: [Text]
+ , listenInterval :: NominalDiffTime
+ } deriving Show
+
+parse :: FilePath -> IO (Either Text Conf)
+parse path =
+ (flip fmap) (Conf.readConfig path) (\configOrError -> do
+ conf <- configOrError
+ Conf <$>
+ Conf.lookup "url" conf <*>
+ Conf.lookup "mailFrom" conf <*>
+ Conf.lookup "mailTo" conf <*>
+ Conf.lookup "properties" conf <*>
+ Conf.lookup "listenInterval" conf
+ )