{-# LANGUAGE UndecidableInstances #-}

module Shrun.Configuration.Data.ConsoleLogging
  ( -- * Types
    ConsoleLoggingP (..),
    ConsoleLoggingArgs,
    ConsoleLoggingToml,
    ConsoleLoggingMerged,
    ConsoleLoggingEnv,
    ConsoleLogCmdSwitch (..),

    -- * Functions
    mergeConsoleLogging,
    toEnv,

    -- * Misc
    defaultMerged,
  )
where

import Shrun.Configuration.Data.ConfigPhase
  ( ConfigPhase
      ( ConfigPhaseArgs,
        ConfigPhaseEnv,
        ConfigPhaseMerged,
        ConfigPhaseToml
      ),
    ConfigPhaseF,
    ConfigPhaseMaybeF,
    LineTruncF,
    SwitchF,
  )
import Shrun.Configuration.Data.ConsoleLogging.TimerFormat (TimerFormat)
import Shrun.Configuration.Data.StripControl (ConsoleLogStripControl)
import Shrun.Configuration.Data.Truncation
  ( TruncRegion (TruncCommandName),
    Truncation,
    configToLineTrunc,
    decodeCommandNameTrunc,
    decodeLineTrunc,
  )
import Shrun.Configuration.Data.WithDisabled (WithDisabled, (<>?), (<>?.), (<>??))
import Shrun.Configuration.Data.WithDisabled qualified as WD
import Shrun.Configuration.Default (Default (def))
import Shrun.Prelude

-- | Switch for command logging in console logs.
data ConsoleLogCmdSwitch
  = ConsoleLogCmdOff
  | ConsoleLogCmdOn
  deriving stock (ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool
(ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool)
-> (ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool)
-> Eq ConsoleLogCmdSwitch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool
== :: ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool
$c/= :: ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool
/= :: ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch -> Bool
Eq, Int -> ConsoleLogCmdSwitch -> ShowS
[ConsoleLogCmdSwitch] -> ShowS
ConsoleLogCmdSwitch -> String
(Int -> ConsoleLogCmdSwitch -> ShowS)
-> (ConsoleLogCmdSwitch -> String)
-> ([ConsoleLogCmdSwitch] -> ShowS)
-> Show ConsoleLogCmdSwitch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConsoleLogCmdSwitch -> ShowS
showsPrec :: Int -> ConsoleLogCmdSwitch -> ShowS
$cshow :: ConsoleLogCmdSwitch -> String
show :: ConsoleLogCmdSwitch -> String
$cshowList :: [ConsoleLogCmdSwitch] -> ShowS
showList :: [ConsoleLogCmdSwitch] -> ShowS
Show)

instance Default ConsoleLogCmdSwitch where
  def :: ConsoleLogCmdSwitch
def = ConsoleLogCmdSwitch
ConsoleLogCmdOff

instance
  ( k ~ An_Iso,
    a ~ Bool,
    b ~ Bool
  ) =>
  LabelOptic
    "boolIso"
    k
    ConsoleLogCmdSwitch
    ConsoleLogCmdSwitch
    a
    b
  where
  labelOptic :: Optic k NoIx ConsoleLogCmdSwitch ConsoleLogCmdSwitch a b
labelOptic =
    (ConsoleLogCmdSwitch -> a)
-> (b -> ConsoleLogCmdSwitch)
-> Iso ConsoleLogCmdSwitch ConsoleLogCmdSwitch a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
      (\cases ConsoleLogCmdSwitch
ConsoleLogCmdOn -> a
Bool
True; ConsoleLogCmdSwitch
ConsoleLogCmdOff -> a
Bool
False)
      (\cases b
Bool
True -> ConsoleLogCmdSwitch
ConsoleLogCmdOn; b
Bool
False -> ConsoleLogCmdSwitch
ConsoleLogCmdOff)

-- | Holds command logging config.
type ConsoleLoggingP :: ConfigPhase -> Type
data ConsoleLoggingP p = MkConsoleLoggingP
  { -- | Whether command logging is enabled.
    forall (p :: ConfigPhase).
ConsoleLoggingP p -> SwitchF p ConsoleLogCmdSwitch
commandLogging :: SwitchF p ConsoleLogCmdSwitch,
    -- | Command name truncation.
    forall (p :: ConfigPhase).
ConsoleLoggingP p
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
commandNameTrunc :: ConfigPhaseMaybeF p (Truncation TruncCommandName),
    -- | Line truncation.
    forall (p :: ConfigPhase). ConsoleLoggingP p -> LineTruncF p
lineTrunc :: LineTruncF p,
    -- | Strip control.
    forall (p :: ConfigPhase).
ConsoleLoggingP p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
stripControl :: ConfigPhaseF p ConsoleLogStripControl,
    -- | How to format the timer.
    forall (p :: ConfigPhase).
ConsoleLoggingP p -> ConfigPhaseF p TimerFormat
timerFormat :: ConfigPhaseF p TimerFormat
  }

instance
  ( k ~ A_Lens,
    a ~ SwitchF p ConsoleLogCmdSwitch,
    b ~ SwitchF p ConsoleLogCmdSwitch
  ) =>
  LabelOptic "commandLogging" k (ConsoleLoggingP p) (ConsoleLoggingP p) a b
  where
  labelOptic :: Optic k NoIx (ConsoleLoggingP p) (ConsoleLoggingP p) a b
labelOptic =
    LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
 -> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b)
-> LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkConsoleLoggingP
             SwitchF p ConsoleLogCmdSwitch
_commandLogging
             ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
             LineTruncF p
_lineTrunc
             ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
             ConfigPhaseF p TimerFormat
_timerFormat
           ) ->
          (b -> ConsoleLoggingP p) -> f b -> f (ConsoleLoggingP p)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \b
commandLogging' ->
                SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
                  b
SwitchF p ConsoleLogCmdSwitch
commandLogging'
                  ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
                  LineTruncF p
_lineTrunc
                  ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
                  ConfigPhaseF p TimerFormat
_timerFormat
            )
            (a -> f b
f a
SwitchF p ConsoleLogCmdSwitch
_commandLogging)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ ConfigPhaseMaybeF p (Truncation TruncCommandName),
    b ~ ConfigPhaseMaybeF p (Truncation TruncCommandName)
  ) =>
  LabelOptic "commandNameTrunc" k (ConsoleLoggingP p) (ConsoleLoggingP p) a b
  where
  labelOptic :: Optic k NoIx (ConsoleLoggingP p) (ConsoleLoggingP p) a b
labelOptic =
    LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
 -> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b)
-> LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkConsoleLoggingP
             SwitchF p ConsoleLogCmdSwitch
_commandLogging
             ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
             LineTruncF p
_lineTrunc
             ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
             ConfigPhaseF p TimerFormat
_timerFormat
           ) ->
          (b -> ConsoleLoggingP p) -> f b -> f (ConsoleLoggingP p)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \b
commandNameTrunc' ->
                SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
                  SwitchF p ConsoleLogCmdSwitch
_commandLogging
                  b
ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
commandNameTrunc'
                  LineTruncF p
_lineTrunc
                  ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
                  ConfigPhaseF p TimerFormat
_timerFormat
            )
            (a -> f b
f a
ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ LineTruncF p,
    b ~ LineTruncF p
  ) =>
  LabelOptic "lineTrunc" k (ConsoleLoggingP p) (ConsoleLoggingP p) a b
  where
  labelOptic :: Optic k NoIx (ConsoleLoggingP p) (ConsoleLoggingP p) a b
labelOptic =
    LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
 -> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b)
-> LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkConsoleLoggingP
             SwitchF p ConsoleLogCmdSwitch
_commandLogging
             ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
             LineTruncF p
_lineTrunc
             ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
             ConfigPhaseF p TimerFormat
_timerFormat
           ) ->
          (b -> ConsoleLoggingP p) -> f b -> f (ConsoleLoggingP p)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \b
lineTrunc' ->
                SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
                  SwitchF p ConsoleLogCmdSwitch
_commandLogging
                  ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
                  b
LineTruncF p
lineTrunc'
                  ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
                  ConfigPhaseF p TimerFormat
_timerFormat
            )
            (a -> f b
f a
LineTruncF p
_lineTrunc)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ ConfigPhaseF p ConsoleLogStripControl,
    b ~ ConfigPhaseF p ConsoleLogStripControl
  ) =>
  LabelOptic "stripControl" k (ConsoleLoggingP p) (ConsoleLoggingP p) a b
  where
  labelOptic :: Optic k NoIx (ConsoleLoggingP p) (ConsoleLoggingP p) a b
labelOptic =
    LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
 -> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b)
-> LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkConsoleLoggingP
             SwitchF p ConsoleLogCmdSwitch
_commandLogging
             ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
             LineTruncF p
_lineTrunc
             ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
             ConfigPhaseF p TimerFormat
_timerFormat
           ) ->
          (b -> ConsoleLoggingP p) -> f b -> f (ConsoleLoggingP p)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( \b
stripControl' ->
                SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
                  SwitchF p ConsoleLogCmdSwitch
_commandLogging
                  ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
                  LineTruncF p
_lineTrunc
                  b
ConfigPhaseF p (StripControl 'StripControlConsoleLog)
stripControl'
                  ConfigPhaseF p TimerFormat
_timerFormat
            )
            (a -> f b
f a
ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ ConfigPhaseF p TimerFormat,
    b ~ ConfigPhaseF p TimerFormat
  ) =>
  LabelOptic "timerFormat" k (ConsoleLoggingP p) (ConsoleLoggingP p) a b
  where
  labelOptic :: Optic k NoIx (ConsoleLoggingP p) (ConsoleLoggingP p) a b
labelOptic =
    LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
 -> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b)
-> LensVL (ConsoleLoggingP p) (ConsoleLoggingP p) a b
-> Lens (ConsoleLoggingP p) (ConsoleLoggingP p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         ( MkConsoleLoggingP
             SwitchF p ConsoleLogCmdSwitch
_commandLogging
             ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
             LineTruncF p
_lineTrunc
             ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
             ConfigPhaseF p TimerFormat
_timerFormat
           ) ->
          (b -> ConsoleLoggingP p) -> f b -> f (ConsoleLoggingP p)
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            ( SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
                SwitchF p ConsoleLogCmdSwitch
_commandLogging
                ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
_commandNameTrunc
                LineTruncF p
_lineTrunc
                ConfigPhaseF p (StripControl 'StripControlConsoleLog)
_stripControl
            )
            (a -> f b
f a
ConfigPhaseF p TimerFormat
_timerFormat)
  {-# INLINE labelOptic #-}

type ConsoleLoggingArgs = ConsoleLoggingP ConfigPhaseArgs

type ConsoleLoggingToml = ConsoleLoggingP ConfigPhaseToml

type ConsoleLoggingMerged = ConsoleLoggingP ConfigPhaseMerged

type ConsoleLoggingEnv = ConsoleLoggingP ConfigPhaseEnv

deriving stock instance Eq (ConsoleLoggingP ConfigPhaseArgs)

deriving stock instance Show (ConsoleLoggingP ConfigPhaseArgs)

deriving stock instance Eq (ConsoleLoggingP ConfigPhaseToml)

deriving stock instance Show (ConsoleLoggingP ConfigPhaseToml)

deriving stock instance Eq (ConsoleLoggingP ConfigPhaseMerged)

deriving stock instance Show (ConsoleLoggingP ConfigPhaseMerged)

instance
  ( Default (SwitchF p ConsoleLogCmdSwitch),
    Default (ConfigPhaseMaybeF p (Truncation TruncCommandName)),
    Default (LineTruncF p),
    Default (ConfigPhaseF p ConsoleLogStripControl),
    Default (ConfigPhaseF p TimerFormat)
  ) =>
  Default (ConsoleLoggingP p)
  where
  def :: ConsoleLoggingP p
def =
    MkConsoleLoggingP
      { commandLogging :: SwitchF p ConsoleLogCmdSwitch
commandLogging = SwitchF p ConsoleLogCmdSwitch
forall a. Default a => a
def,
        commandNameTrunc :: ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
commandNameTrunc = ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
forall a. Default a => a
def,
        lineTrunc :: LineTruncF p
lineTrunc = LineTruncF p
forall a. Default a => a
def,
        stripControl :: ConfigPhaseF p (StripControl 'StripControlConsoleLog)
stripControl = ConfigPhaseF p (StripControl 'StripControlConsoleLog)
forall a. Default a => a
def,
        timerFormat :: ConfigPhaseF p TimerFormat
timerFormat = ConfigPhaseF p TimerFormat
forall a. Default a => a
def
      }

-- | Merges args and toml configs.
mergeConsoleLogging ::
  ( HasCallStack,
    MonadTerminal m
  ) =>
  ConsoleLoggingArgs ->
  Maybe ConsoleLoggingToml ->
  m ConsoleLoggingMerged
mergeConsoleLogging :: forall (m :: Type -> Type).
(HasCallStack, MonadTerminal m) =>
ConsoleLoggingP 'ConfigPhaseArgs
-> Maybe (ConsoleLoggingP 'ConfigPhaseToml)
-> m ConsoleLoggingMerged
mergeConsoleLogging ConsoleLoggingP 'ConfigPhaseArgs
args Maybe (ConsoleLoggingP 'ConfigPhaseToml)
mToml = do
  Maybe (Truncation 'TruncLine)
lineTrunc <-
    WithDisabled LineTruncation -> m (Maybe (Truncation 'TruncLine))
forall (m :: Type -> Type).
(HasCallStack, MonadTerminal m) =>
WithDisabled LineTruncation -> m (Maybe (Truncation 'TruncLine))
configToLineTrunc (WithDisabled LineTruncation -> m (Maybe (Truncation 'TruncLine)))
-> WithDisabled LineTruncation -> m (Maybe (Truncation 'TruncLine))
forall a b. (a -> b) -> a -> b
$ (ConsoleLoggingP 'ConfigPhaseArgs
args ConsoleLoggingP 'ConfigPhaseArgs
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseArgs)
     (WithDisabled LineTruncation)
-> WithDisabled LineTruncation
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseArgs)
  (WithDisabled LineTruncation)
#lineTrunc) WithDisabled LineTruncation
-> Maybe LineTruncation -> WithDisabled LineTruncation
forall a. WithDisabled a -> Maybe a -> WithDisabled a
<>? (ConsoleLoggingP 'ConfigPhaseToml
toml ConsoleLoggingP 'ConfigPhaseToml
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseToml)
     (Maybe LineTruncation)
-> Maybe LineTruncation
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseToml)
  (Maybe LineTruncation)
#lineTrunc)

  pure
    $ MkConsoleLoggingP
      { commandLogging :: SwitchF 'ConfigPhaseMerged ConsoleLogCmdSwitch
commandLogging =
          WithDisabled ConsoleLogCmdSwitch -> ConsoleLogCmdSwitch
forall a. Default a => WithDisabled a -> a
WD.fromDefault
            ( Optic' An_Iso NoIx ConsoleLogCmdSwitch Bool
-> Bool -> ConsoleLogCmdSwitch
forall k (is :: IxList) t b.
Is k A_Review =>
Optic' k is t b -> b -> t
review Optic' An_Iso NoIx ConsoleLogCmdSwitch Bool
#boolIso
                (Bool -> ConsoleLogCmdSwitch)
-> WithDisabled Bool -> WithDisabled ConsoleLogCmdSwitch
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> WithDisabled Bool
argsCommandLogging
                WithDisabled Bool -> Maybe Bool -> WithDisabled Bool
forall a. WithDisabled a -> Maybe a -> WithDisabled a
<>? (ConsoleLoggingP 'ConfigPhaseToml
toml ConsoleLoggingP 'ConfigPhaseToml
-> Optic'
     A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseToml) (Maybe Bool)
-> Maybe Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseToml) (Maybe Bool)
#commandLogging)
            ),
        commandNameTrunc :: ConfigPhaseMaybeF 'ConfigPhaseMerged (Truncation 'TruncCommandName)
commandNameTrunc = (ConsoleLoggingP 'ConfigPhaseArgs
args ConsoleLoggingP 'ConfigPhaseArgs
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseArgs)
     (WithDisabled (Truncation 'TruncCommandName))
-> WithDisabled (Truncation 'TruncCommandName)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseArgs)
  (WithDisabled (Truncation 'TruncCommandName))
#commandNameTrunc) WithDisabled (Truncation 'TruncCommandName)
-> Maybe (Truncation 'TruncCommandName)
-> Maybe (Truncation 'TruncCommandName)
forall a. WithDisabled a -> Maybe a -> Maybe a
<>?? (ConsoleLoggingP 'ConfigPhaseToml
toml ConsoleLoggingP 'ConfigPhaseToml
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseToml)
     (Maybe (Truncation 'TruncCommandName))
-> Maybe (Truncation 'TruncCommandName)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseToml)
  (Maybe (Truncation 'TruncCommandName))
#commandNameTrunc),
        Maybe (Truncation 'TruncLine)
LineTruncF 'ConfigPhaseMerged
lineTrunc :: LineTruncF 'ConfigPhaseMerged
lineTrunc :: Maybe (Truncation 'TruncLine)
lineTrunc,
        stripControl :: ConfigPhaseF
  'ConfigPhaseMerged (StripControl 'StripControlConsoleLog)
stripControl =
          (ConsoleLoggingP 'ConfigPhaseArgs
args ConsoleLoggingP 'ConfigPhaseArgs
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseArgs)
     (WithDisabled (StripControl 'StripControlConsoleLog))
-> WithDisabled (StripControl 'StripControlConsoleLog)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseArgs)
  (WithDisabled (StripControl 'StripControlConsoleLog))
#stripControl) WithDisabled (StripControl 'StripControlConsoleLog)
-> Maybe (StripControl 'StripControlConsoleLog)
-> StripControl 'StripControlConsoleLog
forall a. Default a => WithDisabled a -> Maybe a -> a
<>?. (ConsoleLoggingP 'ConfigPhaseToml
toml ConsoleLoggingP 'ConfigPhaseToml
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseToml)
     (Maybe (StripControl 'StripControlConsoleLog))
-> Maybe (StripControl 'StripControlConsoleLog)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseToml)
  (Maybe (StripControl 'StripControlConsoleLog))
#stripControl),
        timerFormat :: ConfigPhaseF 'ConfigPhaseMerged TimerFormat
timerFormat =
          (ConsoleLoggingP 'ConfigPhaseArgs
args ConsoleLoggingP 'ConfigPhaseArgs
-> Optic'
     A_Lens
     NoIx
     (ConsoleLoggingP 'ConfigPhaseArgs)
     (WithDisabled TimerFormat)
-> WithDisabled TimerFormat
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ConsoleLoggingP 'ConfigPhaseArgs)
  (WithDisabled TimerFormat)
#timerFormat) WithDisabled TimerFormat -> Maybe TimerFormat -> TimerFormat
forall a. Default a => WithDisabled a -> Maybe a -> a
<>?. (ConsoleLoggingP 'ConfigPhaseToml
toml ConsoleLoggingP 'ConfigPhaseToml
-> Optic'
     A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseToml) (Maybe TimerFormat)
-> Maybe TimerFormat
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseToml) (Maybe TimerFormat)
#timerFormat)
      }
  where
    -- Convert WithDisabled () -> WithDisabled Bool for below operation.
    argsCommandLogging :: WithDisabled Bool
    argsCommandLogging :: WithDisabled Bool
argsCommandLogging = ConsoleLoggingP 'ConfigPhaseArgs
args ConsoleLoggingP 'ConfigPhaseArgs
-> Optic'
     A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseArgs) (WithDisabled ())
-> WithDisabled ()
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (ConsoleLoggingP 'ConfigPhaseArgs) (WithDisabled ())
#commandLogging WithDisabled () -> Bool -> WithDisabled Bool
forall (f :: Type -> Type) a b. Functor f => f a -> b -> f b
$> Bool
True

    toml :: ConsoleLoggingP 'ConfigPhaseToml
toml = ConsoleLoggingP 'ConfigPhaseToml
-> Maybe (ConsoleLoggingP 'ConfigPhaseToml)
-> ConsoleLoggingP 'ConfigPhaseToml
forall a. a -> Maybe a -> a
fromMaybe ConsoleLoggingP 'ConfigPhaseToml
defaultToml Maybe (ConsoleLoggingP 'ConfigPhaseToml)
mToml

instance DecodeTOML ConsoleLoggingToml where
  tomlDecoder :: Decoder (ConsoleLoggingP 'ConfigPhaseToml)
tomlDecoder =
    Maybe Bool
-> Maybe (Truncation 'TruncCommandName)
-> Maybe LineTruncation
-> Maybe (StripControl 'StripControlConsoleLog)
-> Maybe TimerFormat
-> ConsoleLoggingP 'ConfigPhaseToml
SwitchF 'ConfigPhaseToml ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF
     'ConfigPhaseToml (Truncation 'TruncCommandName)
-> LineTruncF 'ConfigPhaseToml
-> ConfigPhaseF
     'ConfigPhaseToml (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF 'ConfigPhaseToml TimerFormat
-> ConsoleLoggingP 'ConfigPhaseToml
forall (p :: ConfigPhase).
SwitchF p ConsoleLogCmdSwitch
-> ConfigPhaseMaybeF p (Truncation 'TruncCommandName)
-> LineTruncF p
-> ConfigPhaseF p (StripControl 'StripControlConsoleLog)
-> ConfigPhaseF p TimerFormat
-> ConsoleLoggingP p
MkConsoleLoggingP
      (Maybe Bool
 -> Maybe (Truncation 'TruncCommandName)
 -> Maybe LineTruncation
 -> Maybe (StripControl 'StripControlConsoleLog)
 -> Maybe TimerFormat
 -> ConsoleLoggingP 'ConfigPhaseToml)
-> Decoder (Maybe Bool)
-> Decoder
     (Maybe (Truncation 'TruncCommandName)
      -> Maybe LineTruncation
      -> Maybe (StripControl 'StripControlConsoleLog)
      -> Maybe TimerFormat
      -> ConsoleLoggingP 'ConfigPhaseToml)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder (Maybe Bool)
decodeCommandLogging
      Decoder
  (Maybe (Truncation 'TruncCommandName)
   -> Maybe LineTruncation
   -> Maybe (StripControl 'StripControlConsoleLog)
   -> Maybe TimerFormat
   -> ConsoleLoggingP 'ConfigPhaseToml)
-> Decoder (Maybe (Truncation 'TruncCommandName))
-> Decoder
     (Maybe LineTruncation
      -> Maybe (StripControl 'StripControlConsoleLog)
      -> Maybe TimerFormat
      -> ConsoleLoggingP 'ConfigPhaseToml)
forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe (Truncation 'TruncCommandName))
decodeCommandNameTrunc
      Decoder
  (Maybe LineTruncation
   -> Maybe (StripControl 'StripControlConsoleLog)
   -> Maybe TimerFormat
   -> ConsoleLoggingP 'ConfigPhaseToml)
-> Decoder (Maybe LineTruncation)
-> Decoder
     (Maybe (StripControl 'StripControlConsoleLog)
      -> Maybe TimerFormat -> ConsoleLoggingP 'ConfigPhaseToml)
forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe LineTruncation)
decodeLineTrunc
      Decoder
  (Maybe (StripControl 'StripControlConsoleLog)
   -> Maybe TimerFormat -> ConsoleLoggingP 'ConfigPhaseToml)
-> Decoder (Maybe (StripControl 'StripControlConsoleLog))
-> Decoder (Maybe TimerFormat -> ConsoleLoggingP 'ConfigPhaseToml)
forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe (StripControl 'StripControlConsoleLog))
decodeStripControl
      Decoder (Maybe TimerFormat -> ConsoleLoggingP 'ConfigPhaseToml)
-> Decoder (Maybe TimerFormat)
-> Decoder (ConsoleLoggingP 'ConfigPhaseToml)
forall a b. Decoder (a -> b) -> Decoder a -> Decoder b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Decoder (Maybe TimerFormat)
decodeTimerFormat

decodeCommandLogging :: Decoder (Maybe Bool)
decodeCommandLogging :: Decoder (Maybe Bool)
decodeCommandLogging = Decoder Bool -> Text -> Decoder (Maybe Bool)
forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder Bool
forall a. DecodeTOML a => Decoder a
tomlDecoder Text
"command"

decodeStripControl :: Decoder (Maybe ConsoleLogStripControl)
decodeStripControl :: Decoder (Maybe (StripControl 'StripControlConsoleLog))
decodeStripControl = Decoder (StripControl 'StripControlConsoleLog)
-> Text -> Decoder (Maybe (StripControl 'StripControlConsoleLog))
forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder (StripControl 'StripControlConsoleLog)
forall a. DecodeTOML a => Decoder a
tomlDecoder Text
"strip-control"

decodeTimerFormat :: Decoder (Maybe TimerFormat)
decodeTimerFormat :: Decoder (Maybe TimerFormat)
decodeTimerFormat = Decoder TimerFormat -> Text -> Decoder (Maybe TimerFormat)
forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder TimerFormat
forall a. DecodeTOML a => Decoder a
tomlDecoder Text
"timer-format"

toEnv :: ConsoleLoggingMerged -> ConsoleLoggingEnv
toEnv :: ConsoleLoggingMerged -> ConsoleLoggingEnv
toEnv ConsoleLoggingMerged
merged =
  MkConsoleLoggingP
    { commandLogging :: SwitchF 'ConfigPhaseEnv ConsoleLogCmdSwitch
commandLogging = ConsoleLoggingMerged
merged ConsoleLoggingMerged
-> Optic' A_Lens NoIx ConsoleLoggingMerged ConsoleLogCmdSwitch
-> ConsoleLogCmdSwitch
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ConsoleLoggingMerged ConsoleLogCmdSwitch
#commandLogging,
      commandNameTrunc :: ConfigPhaseMaybeF 'ConfigPhaseEnv (Truncation 'TruncCommandName)
commandNameTrunc = ConsoleLoggingMerged
merged ConsoleLoggingMerged
-> Optic'
     A_Lens
     NoIx
     ConsoleLoggingMerged
     (Maybe (Truncation 'TruncCommandName))
-> Maybe (Truncation 'TruncCommandName)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  ConsoleLoggingMerged
  (Maybe (Truncation 'TruncCommandName))
#commandNameTrunc,
      lineTrunc :: LineTruncF 'ConfigPhaseEnv
lineTrunc = ConsoleLoggingMerged
merged ConsoleLoggingMerged
-> Optic'
     A_Lens NoIx ConsoleLoggingMerged (Maybe (Truncation 'TruncLine))
-> Maybe (Truncation 'TruncLine)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx ConsoleLoggingMerged (Maybe (Truncation 'TruncLine))
#lineTrunc,
      stripControl :: ConfigPhaseF 'ConfigPhaseEnv (StripControl 'StripControlConsoleLog)
stripControl = ConsoleLoggingMerged
merged ConsoleLoggingMerged
-> Optic'
     A_Lens
     NoIx
     ConsoleLoggingMerged
     (StripControl 'StripControlConsoleLog)
-> StripControl 'StripControlConsoleLog
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  ConsoleLoggingMerged
  (StripControl 'StripControlConsoleLog)
#stripControl,
      timerFormat :: ConfigPhaseF 'ConfigPhaseEnv TimerFormat
timerFormat = ConsoleLoggingMerged
merged ConsoleLoggingMerged
-> Optic' A_Lens NoIx ConsoleLoggingMerged TimerFormat
-> TimerFormat
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ConsoleLoggingMerged TimerFormat
#timerFormat
    }

defaultToml :: ConsoleLoggingToml
defaultToml :: ConsoleLoggingP 'ConfigPhaseToml
defaultToml =
  MkConsoleLoggingP
    { commandLogging :: SwitchF 'ConfigPhaseToml ConsoleLogCmdSwitch
commandLogging = Maybe Bool
SwitchF 'ConfigPhaseToml ConsoleLogCmdSwitch
forall a. Maybe a
Nothing,
      commandNameTrunc :: ConfigPhaseMaybeF 'ConfigPhaseToml (Truncation 'TruncCommandName)
commandNameTrunc = Maybe (Truncation 'TruncCommandName)
ConfigPhaseMaybeF 'ConfigPhaseToml (Truncation 'TruncCommandName)
forall a. Maybe a
Nothing,
      lineTrunc :: LineTruncF 'ConfigPhaseToml
lineTrunc = Maybe LineTruncation
LineTruncF 'ConfigPhaseToml
forall a. Maybe a
Nothing,
      stripControl :: ConfigPhaseF
  'ConfigPhaseToml (StripControl 'StripControlConsoleLog)
stripControl = Maybe (StripControl 'StripControlConsoleLog)
ConfigPhaseF
  'ConfigPhaseToml (StripControl 'StripControlConsoleLog)
forall a. Maybe a
Nothing,
      timerFormat :: ConfigPhaseF 'ConfigPhaseToml TimerFormat
timerFormat = Maybe TimerFormat
ConfigPhaseF 'ConfigPhaseToml TimerFormat
forall a. Maybe a
Nothing
    }

defaultMerged :: ConsoleLoggingMerged
defaultMerged :: ConsoleLoggingMerged
defaultMerged =
  MkConsoleLoggingP
    { commandLogging :: SwitchF 'ConfigPhaseMerged ConsoleLogCmdSwitch
commandLogging = SwitchF 'ConfigPhaseMerged ConsoleLogCmdSwitch
ConsoleLogCmdSwitch
forall a. Default a => a
def,
      commandNameTrunc :: ConfigPhaseMaybeF 'ConfigPhaseMerged (Truncation 'TruncCommandName)
commandNameTrunc = Maybe (Truncation 'TruncCommandName)
ConfigPhaseMaybeF 'ConfigPhaseMerged (Truncation 'TruncCommandName)
forall a. Maybe a
Nothing,
      lineTrunc :: LineTruncF 'ConfigPhaseMerged
lineTrunc = Maybe (Truncation 'TruncLine)
LineTruncF 'ConfigPhaseMerged
forall a. Maybe a
Nothing,
      stripControl :: ConfigPhaseF
  'ConfigPhaseMerged (StripControl 'StripControlConsoleLog)
stripControl = StripControl 'StripControlConsoleLog
ConfigPhaseF
  'ConfigPhaseMerged (StripControl 'StripControlConsoleLog)
forall a. Default a => a
def,
      timerFormat :: ConfigPhaseF 'ConfigPhaseMerged TimerFormat
timerFormat = TimerFormat
ConfigPhaseF 'ConfigPhaseMerged TimerFormat
forall a. Default a => a
def
    }