{-# LANGUAGE NoImplicitPrelude #-}
module RIO.Prelude.Simple
( SimpleApp
, runSimpleApp
) where
import RIO.Prelude.Reexports
import RIO.Prelude.Logger
import RIO.Prelude.Lens
import RIO.Prelude.RIO
import RIO.Process
import System.Environment (lookupEnv)
data SimpleApp = SimpleApp
{ saLogFunc :: !LogFunc
, saProcessContext :: !ProcessContext
}
instance HasLogFunc SimpleApp where
logFuncL = lens saLogFunc (\x y -> x { saLogFunc = y })
instance HasProcessContext SimpleApp where
processContextL = lens saProcessContext (\x y -> x { saProcessContext = y })
runSimpleApp :: MonadIO m => RIO SimpleApp a -> m a
runSimpleApp m = liftIO $ do
verbose <- isJust <$> lookupEnv "RIO_VERBOSE"
lo <- logOptionsHandle stderr verbose
pc <- mkDefaultProcessContext
withLogFunc lo $ \lf ->
let simpleApp = SimpleApp
{ saLogFunc = lf
, saProcessContext = pc
}
in runRIO simpleApp m