{-# LANGUAGE UndecidableInstances #-}

-- | Provides types and typeclasses for our environment.
module Shrun.Configuration.Env.Types
  ( -- * \"HasX\" style typeclasses
    HasCommands (..),
    prependCompletedCommand,
    HasCommandLogging (..),
    HasCommonLogging (..),
    HasConsoleLogging (..),
    HasFileLogging (..),
    HasTimeout (..),
    HasInit (..),
    HasAnyError (..),
    setAnyErrorTrue,
    HasNotifyConfig (..),

    -- * Types
    Env (..),
  )
where

import Shrun.Configuration.Data.CommandLogging (CommandLoggingEnv)
import Shrun.Configuration.Data.CommonLogging (CommonLoggingEnv)
import Shrun.Configuration.Data.ConfigPhase (ConfigPhase (ConfigPhaseEnv))
import Shrun.Configuration.Data.ConsoleLogging (ConsoleLoggingEnv)
import Shrun.Configuration.Data.Core (CoreConfigP)
import Shrun.Configuration.Data.Core.Timeout (Timeout)
import Shrun.Configuration.Data.FileLogging (FileLoggingEnv)
import Shrun.Configuration.Data.Notify (NotifyEnv)
import Shrun.Data.Command (CommandP1)
import Shrun.Logging.Types (LogRegion)
import Shrun.Prelude

-- | The commands themselves.
class HasCommands env where
  getCommands :: env -> NESeq CommandP1

  getCompletedCommands :: env -> TVar (Seq CommandP1)

-- | Timeout, if any.
class HasTimeout env where
  getTimeout :: env -> Maybe Timeout

-- | Init, if any.
class HasInit env where
  getInit :: env -> Maybe Text

class HasCommandLogging env where
  getCommandLogging :: env -> CommandLoggingEnv

class HasCommonLogging env where
  getCommonLogging :: env -> CommonLoggingEnv

class HasConsoleLogging env r where
  getConsoleLogging :: env -> Tuple2 ConsoleLoggingEnv (TBQueue (LogRegion r))

class HasFileLogging env where
  getFileLogging :: env -> Maybe FileLoggingEnv

class HasAnyError env where
  -- | Retrieves the anyError flag.
  getAnyError :: env -> TVar Bool

-- | The main 'Env' type used by Shrun.
data Env r = MkEnv
  { forall r. Env r -> CoreConfigP 'ConfigPhaseEnv
config :: CoreConfigP ConfigPhaseEnv,
    -- | Holds a sequence of commands that have completed. Used so we can
    -- determine which commands have /not/ completed if we time out.
    forall r. Env r -> TVar (Seq CommandP1)
completedCommands :: TVar (Seq CommandP1),
    -- | Console log queue.
    forall r. Env r -> TBQueue (LogRegion r)
consoleLogQueue :: ~(TBQueue (LogRegion r)),
    -- | Holds the anyError flag, signaling if any command exited with an
    -- error.
    forall r. Env r -> TVar Bool
anyError :: TVar Bool,
    -- | Holds notification environment.
    -- | Commands
    forall r. Env r -> NESeq CommandP1
commands :: NESeq CommandP1
  }

instance
  ( k ~ A_Lens,
    a ~ CoreConfigP ConfigPhaseEnv,
    b ~ CoreConfigP ConfigPhaseEnv
  ) =>
  LabelOptic "config" k (Env r) (Env r) a b
  where
  labelOptic :: Optic k NoIx (Env r) (Env r) a b
labelOptic =
    LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b)
-> LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkEnv
             CoreConfigP 'ConfigPhaseEnv
_config
             TVar (Seq CommandP1)
_completedCommands
             TBQueue (LogRegion r)
_consoleLogQueue
             TVar Bool
_anyError
             NESeq CommandP1
_commands
           ) ->
          (CoreConfigP 'ConfigPhaseEnv -> Env r)
-> f (CoreConfigP 'ConfigPhaseEnv) -> f (Env r)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \CoreConfigP 'ConfigPhaseEnv
config' ->
                CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
forall r.
CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
MkEnv
                  CoreConfigP 'ConfigPhaseEnv
config'
                  TVar (Seq CommandP1)
_completedCommands
                  TBQueue (LogRegion r)
_consoleLogQueue
                  TVar Bool
_anyError
                  NESeq CommandP1
_commands
            )
            (a -> f b
f a
CoreConfigP 'ConfigPhaseEnv
_config)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ TVar (Seq CommandP1),
    b ~ TVar (Seq CommandP1)
  ) =>
  LabelOptic "completedCommands" k (Env r) (Env r) a b
  where
  labelOptic :: Optic k NoIx (Env r) (Env r) a b
labelOptic =
    LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b)
-> LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkEnv
             CoreConfigP 'ConfigPhaseEnv
_config
             TVar (Seq CommandP1)
_completedCommands
             TBQueue (LogRegion r)
_consoleLogQueue
             TVar Bool
_anyError
             NESeq CommandP1
_commands
           ) ->
          (TVar (Seq CommandP1) -> Env r)
-> f (TVar (Seq CommandP1)) -> f (Env r)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \TVar (Seq CommandP1)
completedCommands' ->
                CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
forall r.
CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
MkEnv
                  CoreConfigP 'ConfigPhaseEnv
_config
                  TVar (Seq CommandP1)
completedCommands'
                  TBQueue (LogRegion r)
_consoleLogQueue
                  TVar Bool
_anyError
                  NESeq CommandP1
_commands
            )
            (a -> f b
f a
TVar (Seq CommandP1)
_completedCommands)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ TBQueue (LogRegion r),
    b ~ TBQueue (LogRegion r)
  ) =>
  LabelOptic "consoleLogQueue" k (Env r) (Env r) a b
  where
  labelOptic :: Optic k NoIx (Env r) (Env r) a b
labelOptic =
    LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b)
-> LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkEnv
             CoreConfigP 'ConfigPhaseEnv
_config
             TVar (Seq CommandP1)
_completedCommands
             TBQueue (LogRegion r)
_consoleLogQueue
             TVar Bool
_anyError
             NESeq CommandP1
_commands
           ) ->
          (TBQueue (LogRegion r) -> Env r)
-> f (TBQueue (LogRegion r)) -> f (Env r)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \TBQueue (LogRegion r)
consoleLogQueue' ->
                CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
forall r.
CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
MkEnv
                  CoreConfigP 'ConfigPhaseEnv
_config
                  TVar (Seq CommandP1)
_completedCommands
                  TBQueue (LogRegion r)
consoleLogQueue'
                  TVar Bool
_anyError
                  NESeq CommandP1
_commands
            )
            (a -> f b
f a
TBQueue (LogRegion r)
_consoleLogQueue)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ TVar Bool,
    b ~ TVar Bool
  ) =>
  LabelOptic "anyError" k (Env r) (Env r) a b
  where
  labelOptic :: Optic k NoIx (Env r) (Env r) a b
labelOptic =
    LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b)
-> LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkEnv
             CoreConfigP 'ConfigPhaseEnv
_config
             TVar (Seq CommandP1)
_completedCommands
             TBQueue (LogRegion r)
_consoleLogQueue
             TVar Bool
_anyError
             NESeq CommandP1
_commands
           ) ->
          (TVar Bool -> Env r) -> f (TVar Bool) -> f (Env r)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \TVar Bool
anyError' ->
                CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
forall r.
CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
MkEnv
                  CoreConfigP 'ConfigPhaseEnv
_config
                  TVar (Seq CommandP1)
_completedCommands
                  TBQueue (LogRegion r)
_consoleLogQueue
                  TVar Bool
anyError'
                  NESeq CommandP1
_commands
            )
            (a -> f b
f a
TVar Bool
_anyError)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ NESeq CommandP1,
    b ~ NESeq CommandP1
  ) =>
  LabelOptic "commands" k (Env r) (Env r) a b
  where
  labelOptic :: Optic k NoIx (Env r) (Env r) a b
labelOptic =
    LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b)
-> LensVL (Env r) (Env r) a b -> Lens (Env r) (Env r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkEnv
             CoreConfigP 'ConfigPhaseEnv
_config
             TVar (Seq CommandP1)
_completedCommands
             TBQueue (LogRegion r)
_consoleLogQueue
             TVar Bool
_anyError
             NESeq CommandP1
_commands
           ) ->
          (NESeq CommandP1 -> Env r) -> f (NESeq CommandP1) -> f (Env r)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
forall r.
CoreConfigP 'ConfigPhaseEnv
-> TVar (Seq CommandP1)
-> TBQueue (LogRegion r)
-> TVar Bool
-> NESeq CommandP1
-> Env r
MkEnv
                CoreConfigP 'ConfigPhaseEnv
_config
                TVar (Seq CommandP1)
_completedCommands
                TBQueue (LogRegion r)
_consoleLogQueue
                TVar Bool
_anyError
            )
            (a -> f b
f a
NESeq CommandP1
_commands)
  {-# INLINE labelOptic #-}

instance HasTimeout (Env r) where
  getTimeout :: Env r -> Maybe Timeout
getTimeout = Optic' A_Lens NoIx (Env r) (Maybe Timeout)
-> Env r -> Maybe Timeout
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     (Maybe Timeout)
     (Maybe Timeout)
-> Optic' A_Lens NoIx (Env r) (Maybe Timeout)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  (Maybe Timeout)
  (Maybe Timeout)
#timeout)

instance HasInit (Env r) where
  getInit :: Env r -> Maybe Text
getInit = Optic' A_Lens NoIx (Env r) (Maybe Text) -> Env r -> Maybe Text
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     (Maybe Text)
     (Maybe Text)
-> Optic' A_Lens NoIx (Env r) (Maybe Text)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  (Maybe Text)
  (Maybe Text)
#init)

instance HasCommandLogging (Env r) where
  getCommandLogging :: Env r -> CommandLoggingEnv
getCommandLogging = Optic' A_Lens NoIx (Env r) CommandLoggingEnv
-> Env r -> CommandLoggingEnv
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     CommandLoggingEnv
     CommandLoggingEnv
-> Optic' A_Lens NoIx (Env r) CommandLoggingEnv
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  CommandLoggingEnv
  CommandLoggingEnv
#commandLogging)

instance HasCommonLogging (Env r) where
  getCommonLogging :: Env r -> CommonLoggingEnv
getCommonLogging = Optic' A_Lens NoIx (Env r) CommonLoggingEnv
-> Env r -> CommonLoggingEnv
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     CommonLoggingEnv
     CommonLoggingEnv
-> Optic' A_Lens NoIx (Env r) CommonLoggingEnv
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  CommonLoggingEnv
  CommonLoggingEnv
#commonLogging)

instance HasConsoleLogging (Env r) r where
  getConsoleLogging :: Env r -> Tuple2 ConsoleLoggingEnv (TBQueue (LogRegion r))
getConsoleLogging Env r
env =
    ( Env r
env Env r
-> Optic' A_Lens NoIx (Env r) ConsoleLoggingEnv
-> ConsoleLoggingEnv
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     ConsoleLoggingEnv
     ConsoleLoggingEnv
-> Optic' A_Lens NoIx (Env r) ConsoleLoggingEnv
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  ConsoleLoggingEnv
  ConsoleLoggingEnv
#consoleLogging,
      Env r
env Env r
-> Optic' A_Lens NoIx (Env r) (TBQueue (LogRegion r))
-> TBQueue (LogRegion r)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (Env r) (TBQueue (LogRegion r))
#consoleLogQueue
    )

instance HasFileLogging (Env r) where
  getFileLogging :: Env r -> Maybe FileLoggingEnv
getFileLogging = Optic' A_Lens NoIx (Env r) (Maybe FileLoggingEnv)
-> Env r -> Maybe FileLoggingEnv
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     (Maybe FileLoggingEnv)
     (Maybe FileLoggingEnv)
-> Optic' A_Lens NoIx (Env r) (Maybe FileLoggingEnv)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  (Maybe FileLoggingEnv)
  (Maybe FileLoggingEnv)
#fileLogging)

instance HasCommands (Env r) where
  getCommands :: Env r -> NESeq CommandP1
getCommands = Optic' A_Lens NoIx (Env r) (NESeq CommandP1)
-> Env r -> NESeq CommandP1
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' A_Lens NoIx (Env r) (NESeq CommandP1)
#commands
  getCompletedCommands :: Env r -> TVar (Seq CommandP1)
getCompletedCommands = Optic' A_Lens NoIx (Env r) (TVar (Seq CommandP1))
-> Env r -> TVar (Seq CommandP1)
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' A_Lens NoIx (Env r) (TVar (Seq CommandP1))
#completedCommands

-- | Prepends a completed command.
prependCompletedCommand ::
  ( HasCallStack,
    HasCommands env,
    MonadReader env m,
    MonadSTM m
  ) =>
  CommandP1 ->
  m ()
prependCompletedCommand :: forall env (m :: Type -> Type).
(HasCallStack, HasCommands env, MonadReader env m, MonadSTM m) =>
CommandP1 -> m ()
prependCompletedCommand CommandP1
command = do
  TVar (Seq CommandP1)
completedCommands <- (env -> TVar (Seq CommandP1)) -> m (TVar (Seq CommandP1))
forall r (m :: Type -> Type) a. MonadReader r m => (r -> a) -> m a
asks env -> TVar (Seq CommandP1)
forall env. HasCommands env => env -> TVar (Seq CommandP1)
getCompletedCommands
  TVar (Seq CommandP1) -> (Seq CommandP1 -> Seq CommandP1) -> m ()
forall (m :: Type -> Type) a.
(HasCallStack, MonadSTM m) =>
TVar a -> (a -> a) -> m ()
modifyTVarA' TVar (Seq CommandP1)
completedCommands (CommandP1
command :<|)

instance HasAnyError (Env r) where
  getAnyError :: Env r -> TVar Bool
getAnyError = Optic' A_Lens NoIx (Env r) (TVar Bool) -> Env r -> TVar Bool
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' A_Lens NoIx (Env r) (TVar Bool)
#anyError

-- | Set anyError to 'True'.
setAnyErrorTrue ::
  ( HasAnyError env,
    HasCallStack,
    MonadReader env m,
    MonadSTM m
  ) =>
  m ()
setAnyErrorTrue :: forall env (m :: Type -> Type).
(HasAnyError env, HasCallStack, MonadReader env m, MonadSTM m) =>
m ()
setAnyErrorTrue = (env -> TVar Bool) -> m (TVar Bool)
forall r (m :: Type -> Type) a. MonadReader r m => (r -> a) -> m a
asks env -> TVar Bool
forall env. HasAnyError env => env -> TVar Bool
getAnyError m (TVar Bool) -> (TVar Bool -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= \TVar Bool
ref -> TVar Bool -> Bool -> m ()
forall (m :: Type -> Type) a.
(HasCallStack, MonadSTM m) =>
TVar a -> a -> m ()
writeTVarA TVar Bool
ref Bool
True

-- | Class for retrieving the notify config.
class HasNotifyConfig env where
  -- | Retrieves the notify config.
  getNotifyConfig :: env -> Maybe NotifyEnv

instance HasNotifyConfig (Env r) where
  getNotifyConfig :: Env r -> Maybe NotifyEnv
getNotifyConfig = Optic' A_Lens NoIx (Env r) (Maybe NotifyEnv)
-> Env r -> Maybe NotifyEnv
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view (Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
#config Optic
  A_Lens
  NoIx
  (Env r)
  (Env r)
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
-> Optic
     A_Lens
     NoIx
     (CoreConfigP 'ConfigPhaseEnv)
     (CoreConfigP 'ConfigPhaseEnv)
     (Maybe NotifyEnv)
     (Maybe NotifyEnv)
-> Optic' A_Lens NoIx (Env r) (Maybe NotifyEnv)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (CoreConfigP 'ConfigPhaseEnv)
  (CoreConfigP 'ConfigPhaseEnv)
  (Maybe NotifyEnv)
  (Maybe NotifyEnv)
#notify)