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.HashMap.Strict as M import Data.ConfigManager.Config import qualified Data.ConfigManager.Reader as R import Data.ConfigManager.Expr readConfig :: FilePath -> IO (Either Text Config) readConfig = R.readConfig 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)