-- * Interpreters

runDocker
    :: forall r a.
      ( Member (Exception DockerEx) r
      , Member Filesystem r
      , Member (Exception FilesystemEx) r
      , Member Proc r)
    => Eff (Docker ': r) a
    -> Eff r a
runDocker = handleRelay return handle
  where
    handle :: Handler Docker r a
    handle (RemoveImage img imgs) k = procRemoveImage (img:imgs) >>= k
    handle (BuildImage path img)  k = procBuildImage path img >>= k
    handle (TagImage img tag)     k = procTagImage img tag >>= k
    handle (PushImage img)        k = procPushImage img >>= k
    handle (PullImage img)        k = procPullImage img >>= k

-- | Push a Docker 'Image' to a remote.
runDocker
    :: forall r a.
      ( Member (Exception DockerEx) r
      , Member Filesystem r
      , Member (Exception FilesystemEx) r
      , Member Proc r)
    => Eff (Docker ': r) a
    -> Eff r a
runDocker = handleRelay return handle
  where
    handle :: Handler Docker r a
    handle (RemoveImage img imgs) k = procRemoveImage (img:imgs) >>= k
    handle (BuildImage path img)  k = procBuildImage path img >>= k
    handle (TagImage img tag)     k = procTagImage img tag >>= k
    handle (PushImage img)        k = procPushImage img >>= k
    handle (PullImage img)        k = procPullImage img >>= k

-- | Push a Docker 'Image' to a remote.
runDocker = handleRelay return handle
  where
    handle :: Handler Docker r a
    handle (RemoveImage img imgs) k = procRemoveImage (img:imgs) >>= k
    handle (BuildImage path img)  k = procBuildImage path img >>= k
    handle (TagImage img tag)     k = procTagImage img tag >>= k
    handle (PushImage img)        k = procPushImage img >>= k
    handle (PullImage img)        k = procPullImage img >>= k

-- | Push a Docker 'Image' to a remote.