-- | The silent formatter does nothing except print the test root folder path, if present.
--
-- This is provided as an explicit formatter so it can print that single line. If you don't want anything at all to be printed, you can just run with no formatters.
--
-- Documentation can be found <https://codedownio.github.io/sandwich/docs/formatters/silent here>.

module Test.Sandwich.Formatters.Silent (
  defaultSilentFormatter

  -- * Options
  , silentFormatterPrintRunRoot
  ) where

import Control.Monad.IO.Class
import Data.String.Interpolate
import Test.Sandwich.Types.RunTree
import Test.Sandwich.Util


data SilentFormatter = SilentFormatter {
  SilentFormatter -> Bool
silentFormatterPrintRunRoot :: Bool
  } deriving (Int -> SilentFormatter -> ShowS
[SilentFormatter] -> ShowS
SilentFormatter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SilentFormatter] -> ShowS
$cshowList :: [SilentFormatter] -> ShowS
show :: SilentFormatter -> String
$cshow :: SilentFormatter -> String
showsPrec :: Int -> SilentFormatter -> ShowS
$cshowsPrec :: Int -> SilentFormatter -> ShowS
Show)

defaultSilentFormatter :: SilentFormatter
defaultSilentFormatter :: SilentFormatter
defaultSilentFormatter = SilentFormatter {
  silentFormatterPrintRunRoot :: Bool
silentFormatterPrintRunRoot = Bool
True
  }

instance Formatter SilentFormatter where
  formatterName :: SilentFormatter -> String
formatterName SilentFormatter
_ = String
"silent-formatter"
  runFormatter :: forall (m :: * -> *).
(MonadLoggerIO m, MonadUnliftIO m, MonadCatch m) =>
SilentFormatter
-> [RunNode BaseContext]
-> Maybe (CommandLineOptions ())
-> BaseContext
-> m ()
runFormatter SilentFormatter
_ [RunNode BaseContext]
_ Maybe (CommandLineOptions ())
_ BaseContext
bc =
    forall (m :: * -> *) a b. Monad m => Maybe a -> (a -> m b) -> m ()
whenJust (BaseContext -> Maybe String
baseContextRunRoot BaseContext
bc) forall a b. (a -> b) -> a -> b
$ \String
runRoot ->
      forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStrLn [i|Run root: #{runRoot}\n|]
  finalizeFormatter :: forall (m :: * -> *).
(MonadIO m, MonadLogger m, MonadCatch m) =>
SilentFormatter -> [RunNode BaseContext] -> BaseContext -> m ()
finalizeFormatter SilentFormatter
_ [RunNode BaseContext]
_ BaseContext
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()