-- | Unlifted "System.Environment".
--
-- @since 0.2.5.0
module UnliftIO.Environment
  ( getArgs
  , getProgName
  , getExecutablePath
  , getEnv
  , lookupEnv
  , setEnv
  , unsetEnv
  , withArgs
  , withProgName
  , getEnvironment
  ) where

import Control.Monad.IO.Unlift
import qualified System.Environment as E

-- | Lifted 'E.getArgs'.
--
-- @since 0.2.5.0
{-# INLINE getArgs #-}
getArgs :: MonadIO m => m [String]
getArgs :: m [String]
getArgs = IO [String] -> m [String]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO [String]
E.getArgs

-- | Lifted 'E.getProgName'.
--
-- @since 0.2.5.0
{-# INLINE getProgName #-}
getProgName :: MonadIO m => m String
getProgName :: m String
getProgName = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO String
E.getProgName

-- | Lifted 'E.getExecutablePath'.
--
-- @since 0.2.5.0
{-# INLINE getExecutablePath #-}
getExecutablePath :: MonadIO m => m FilePath
getExecutablePath :: m String
getExecutablePath = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO String
E.getExecutablePath

-- | Lifted 'E.getEnv'.
--
-- @since 0.2.5.0
{-# INLINE getEnv #-}
getEnv :: MonadIO m => String -> m String
getEnv :: String -> m String
getEnv = IO String -> m String
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO String -> m String)
-> (String -> IO String) -> String -> m String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO String
E.getEnv

-- | Lifted 'E.lookupEnv'.
--
-- @since 0.2.5.0
{-# INLINE lookupEnv #-}
lookupEnv :: MonadIO m => String -> m (Maybe String)
lookupEnv :: String -> m (Maybe String)
lookupEnv = IO (Maybe String) -> m (Maybe String)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe String) -> m (Maybe String))
-> (String -> IO (Maybe String)) -> String -> m (Maybe String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO (Maybe String)
E.lookupEnv

-- | Lifted 'E.setEnv'.
--
-- @since 0.2.5.0
{-# INLINE setEnv #-}
setEnv :: MonadIO m => String -> String -> m ()
setEnv :: String -> String -> m ()
setEnv String
key_ String
value_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> String -> IO ()
E.setEnv String
key_ String
value_)

-- | Lifted 'E.unsetEnv'.
--
-- @since 0.2.5.0
{-# INLINE unsetEnv #-}
unsetEnv :: MonadIO m => String -> m ()
unsetEnv :: String -> m ()
unsetEnv = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (String -> IO ()) -> String -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
E.unsetEnv

-- | Unlifted 'E.withArgs'.
--
-- @since 0.2.5.0
{-# INLINE withArgs #-}
withArgs :: MonadUnliftIO m => [String] -> m a -> m a
withArgs :: [String] -> m a -> m a
withArgs [String]
xs m a
act = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> [String] -> IO a -> IO a
forall a. [String] -> IO a -> IO a
E.withArgs [String]
xs (m a -> IO a
forall a. m a -> IO a
u m a
act))

-- | Unlifted 'E.withProgName'.
--
-- @since 0.2.5.0
{-# INLINE withProgName #-}
withProgName :: MonadUnliftIO m => String -> m a -> m a
withProgName :: String -> m a -> m a
withProgName String
nm m a
act = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
u -> String -> IO a -> IO a
forall a. String -> IO a -> IO a
E.withProgName String
nm (m a -> IO a
forall a. m a -> IO a
u m a
act))

-- | Lifted 'E.getEnvironment'.
--
-- @since 0.2.5.0
{-# INLINE getEnvironment #-}
getEnvironment :: MonadIO m => m [(String, String)]
getEnvironment :: m [(String, String)]
getEnvironment = IO [(String, String)] -> m [(String, String)]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO [(String, String)]
E.getEnvironment