aboutsummaryrefslogtreecommitdiff
path: root/Data/ConfigManager.hs
diff options
context:
space:
mode:
authorJoris2016-03-13 21:26:03 +0100
committerJoris2016-03-13 21:26:03 +0100
commit47623ec732ec19c765c0a1ebffd9b234f81e0d01 (patch)
treea52969d730e64d1303e62efa8c36b03a7be7f1a5 /Data/ConfigManager.hs
Initial commit
Diffstat (limited to 'Data/ConfigManager.hs')
-rw-r--r--Data/ConfigManager.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/Data/ConfigManager.hs b/Data/ConfigManager.hs
new file mode 100644
index 0000000..d972cd8
--- /dev/null
+++ b/Data/ConfigManager.hs
@@ -0,0 +1,27 @@
+module Data.ConfigManager
+ ( readConfig
+ , lookup
+ , lookupDefault
+ ) where
+
+import Prelude hiding (lookup)
+import Text.Read (readMaybe)
+import Control.Monad (join)
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.IO as T
+import qualified Data.HashMap.Strict as M
+
+import Data.ConfigManager.Config
+import Data.ConfigManager.Parser (parseConfig)
+import Data.ConfigManager.Types
+
+readConfig :: FilePath -> IO (Either Text Config)
+readConfig path = parseConfig <$> T.readFile path
+
+lookup :: Read a => Name -> Config -> Maybe a
+lookup name config = join . fmap (readMaybe . T.unpack) $ M.lookup name (hashMap config)
+
+lookupDefault :: Value -> Name -> Config -> Value
+lookupDefault defaultValue name config = M.lookupDefault defaultValue name (hashMap config)