{-# LANGUAGE NoImplicitPrelude #-}

-- | Functions related to Stack's @docker pull@ and @docker reset@ commands.

module Stack.DockerCmd
  ( dockerPullCmd
  , dockerResetCmd
  ) where

import           Stack.Docker ( preventInContainer, pull, reset )
import           Stack.Prelude
import           Stack.Runners ( ShouldReexec (..), withConfig )
import           Stack.Types.Runner ( Runner )

-- | Function underlying the @stack docker pull@ command. Pull the current

-- Docker image.

dockerPullCmd :: () -> RIO Runner ()
dockerPullCmd :: () -> RIO Runner ()
dockerPullCmd () = ShouldReexec -> RIO Config () -> RIO Runner ()
forall a. ShouldReexec -> RIO Config a -> RIO Runner a
withConfig ShouldReexec
NoReexec (RIO Config () -> RIO Runner ()) -> RIO Config () -> RIO Runner ()
forall a b. (a -> b) -> a -> b
$ RIO Config () -> RIO Config ()
forall (m :: * -> *). MonadIO m => m () -> m ()
preventInContainer RIO Config ()
forall env. HasConfig env => RIO env ()
pull

-- | Function underlying the @stack docker reset@ command. Reset the Docker

-- sandbox.

dockerResetCmd ::
     Bool
     -- ^ Delete the sandbox's home directory?

  -> RIO Runner ()
dockerResetCmd :: Bool -> RIO Runner ()
dockerResetCmd = ShouldReexec -> RIO Config () -> RIO Runner ()
forall a. ShouldReexec -> RIO Config a -> RIO Runner a
withConfig ShouldReexec
NoReexec (RIO Config () -> RIO Runner ())
-> (Bool -> RIO Config ()) -> Bool -> RIO Runner ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RIO Config () -> RIO Config ()
forall (m :: * -> *). MonadIO m => m () -> m ()
preventInContainer (RIO Config () -> RIO Config ())
-> (Bool -> RIO Config ()) -> Bool -> RIO Config ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> RIO Config ()
forall env. HasConfig env => Bool -> RIO env ()
reset