{- |
   Module     : Development.Shake.Plus.Config
   License    : MIT
   Stability  : experimental

Utilities in "Development.Shake.Config" lifted to `MonadAction` and well-typed `Path`s.
-}
module Development.Shake.Plus.Config (
  readConfigFile
, readConfigFileWithEnv
, usingConfigFile
, usingConfig
, getConfig
, getConfigKeys
) where

import           Development.Shake
import qualified Development.Shake.Config
import           Development.Shake.Plus.Core
import           Path
import           RIO

-- | Lifted `Development.Shake.Config.readConfigFile` with well-typed path.
readConfigFile :: MonadIO m => Path b File -> m (HashMap String String)
readConfigFile :: Path b File -> m (HashMap String String)
readConfigFile = IO (HashMap String String) -> m (HashMap String String)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (HashMap String String) -> m (HashMap String String))
-> (Path b File -> IO (HashMap String String))
-> Path b File
-> m (HashMap String String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO (HashMap String String)
Development.Shake.Config.readConfigFile (String -> IO (HashMap String String))
-> (Path b File -> String)
-> Path b File
-> IO (HashMap String String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path b File -> String
forall b t. Path b t -> String
toFilePath

-- | Lifted `Development.Shake.Config.readConfigFileWithEnv` with well-typed path.
readConfigFileWithEnv :: MonadIO m => [(String, String)] -> Path b File -> m (HashMap String String)
readConfigFileWithEnv :: [(String, String)] -> Path b File -> m (HashMap String String)
readConfigFileWithEnv [(String, String)]
vars Path b File
file = IO (HashMap String String) -> m (HashMap String String)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (HashMap String String) -> m (HashMap String String))
-> IO (HashMap String String) -> m (HashMap String String)
forall a b. (a -> b) -> a -> b
$ [(String, String)] -> String -> IO (HashMap String String)
Development.Shake.Config.readConfigFileWithEnv [(String, String)]
vars (Path b File -> String
forall b t. Path b t -> String
toFilePath Path b File
file)

-- | Lifted `Development.Shake.Config.usingConfigFile` with well-typed path.
usingConfigFile :: MonadRules m => Path b File -> m ()
usingConfigFile :: Path b File -> m ()
usingConfigFile = Rules () -> m ()
forall (m :: * -> *) a. MonadRules m => Rules a -> m a
liftRules (Rules () -> m ())
-> (Path b File -> Rules ()) -> Path b File -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Rules ()
Development.Shake.Config.usingConfigFile (String -> Rules ())
-> (Path b File -> String) -> Path b File -> Rules ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path b File -> String
forall b t. Path b t -> String
toFilePath

-- | Lifted `Development.Shake.Config.usingConfig`.
usingConfig :: MonadRules m => HashMap String String -> m ()
usingConfig :: HashMap String String -> m ()
usingConfig = Rules () -> m ()
forall (m :: * -> *) a. MonadRules m => Rules a -> m a
liftRules (Rules () -> m ())
-> (HashMap String String -> Rules ())
-> HashMap String String
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap String String -> Rules ()
Development.Shake.Config.usingConfig

-- | Lifted `Development.Shake.Config.getConfig`.
getConfig :: MonadAction m => String -> m (Maybe String)
getConfig :: String -> m (Maybe String)
getConfig = Action (Maybe String) -> m (Maybe String)
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction (Action (Maybe String) -> m (Maybe String))
-> (String -> Action (Maybe String)) -> String -> m (Maybe String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Action (Maybe String)
Development.Shake.Config.getConfig

-- | Lifted `Development.Shake.Config.getConfigKeys`.
getConfigKeys :: MonadAction m => m [String]
getConfigKeys :: m [String]
getConfigKeys = Action [String] -> m [String]
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction Action [String]
Development.Shake.Config.getConfigKeys