From 47623ec732ec19c765c0a1ebffd9b234f81e0d01 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Mar 2016 21:26:03 +0100 Subject: Initial commit --- Data/ConfigManager.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Data/ConfigManager.hs (limited to 'Data/ConfigManager.hs') 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) -- cgit v1.2.3