module B9.B9Monad
( runB9,
runB9Interactive,
B9,
B9Eff,
IsB9,
)
where
import B9.B9Config
import B9.B9Error
import B9.B9Logging
import B9.BuildInfo
import B9.Environment
import B9.Repository
import B9.RepositoryIO
import Control.Eff
import Data.Functor ()
import GHC.Stack
type B9 a = Eff B9Eff a
type B9Eff =
'[ SelectedRemoteRepoReader,
RepoCacheReader,
BuildInfoReader,
LoggerReader,
B9ConfigReader,
EnvironmentReader,
ExcB9,
Lift
IO
]
type IsB9 e = (HasCallStack, Lifted IO e, CommandIO e, B9Eff <:: e)
runB9 :: HasCallStack => B9 a -> B9ConfigAction a
runB9 = runB9Full False
runB9Interactive :: HasCallStack => B9 a -> B9ConfigAction a
runB9Interactive = runB9Full True
runB9Full :: HasCallStack => Bool -> B9 a -> B9ConfigAction a
runB9Full interactive action = do
cfg <- getB9Config
env <- askEnvironment
lift
( runLift
. errorOnException
. runEnvironmentReader env
. runB9ConfigReader cfg
. withLogger
. withBuildInfo interactive
. withRemoteRepos
. withSelectedRemoteRepo
$ action
)