module Chakra.Config where
import qualified System.Envy as Envy
import System.IO (hPutStrLn, stderr)
withAppSettingsFromEnv :: Envy.FromEnv t => (t -> IO ()) -> IO ()
withAppSettingsFromEnv :: (t -> IO ()) -> IO ()
withAppSettingsFromEnv t -> IO ()
f = IO (Either String t)
forall a. FromEnv a => IO (Either String a)
Envy.decodeEnv IO (Either String t) -> (Either String t -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Either String t -> IO ()
callF
where
callF :: Either String t -> IO ()
callF Either String t
x =
case Either String t
x of
Left String
e -> Handle -> String -> IO ()
hPutStrLn Handle
stderr (String
"Error reading env: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
e)
Right t
c -> t -> IO ()
f t
c