diff options
Diffstat (limited to 'Data/ConfigManager.hs')
-rw-r--r-- | Data/ConfigManager.hs | 27 |
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) |