-- | CLI parsing for CommonLoggingArgs
module Shrun.Configuration.Args.Parsing.CommonLogging
  ( commonLoggingParser,
  )
where

import Options.Applicative (Parser)
import Options.Applicative qualified as OA
import Shrun.Configuration.Args.Parsing.Utils qualified as Utils
import Shrun.Configuration.Data.CommonLogging
  ( CommonLoggingArgs,
    CommonLoggingP (MkCommonLoggingP),
  )
import Shrun.Configuration.Data.CommonLogging.KeyHideSwitch
  ( KeyHideSwitch (KeyHideOn),
  )
import Shrun.Configuration.Data.WithDisabled (WithDisabled)
import Shrun.Prelude

commonLoggingParser :: Parser CommonLoggingArgs
commonLoggingParser :: Parser CommonLoggingArgs
commonLoggingParser = WithDisabled KeyHideSwitch -> CommonLoggingArgs
ConfigPhaseF 'ConfigPhaseArgs KeyHideSwitch -> CommonLoggingArgs
forall (p :: ConfigPhase).
ConfigPhaseF p KeyHideSwitch -> CommonLoggingP p
MkCommonLoggingP (WithDisabled KeyHideSwitch -> CommonLoggingArgs)
-> Parser (WithDisabled KeyHideSwitch) -> Parser CommonLoggingArgs
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (WithDisabled KeyHideSwitch)
keyHideParser

keyHideParser :: Parser (WithDisabled KeyHideSwitch)
keyHideParser :: Parser (WithDisabled KeyHideSwitch)
keyHideParser = Parser (Maybe KeyHideSwitch)
-> String -> Parser (WithDisabled KeyHideSwitch)
forall a. Parser (Maybe a) -> String -> Parser (WithDisabled a)
Utils.withDisabledParser Parser (Maybe KeyHideSwitch)
mainParser String
"common-log-key-hide"
  where
    mainParser :: Parser (Maybe KeyHideSwitch)
mainParser =
      Parser KeyHideSwitch -> Parser (Maybe KeyHideSwitch)
forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
OA.optional
        (Parser KeyHideSwitch -> Parser (Maybe KeyHideSwitch))
-> Parser KeyHideSwitch -> Parser (Maybe KeyHideSwitch)
forall a b. (a -> b) -> a -> b
$ KeyHideSwitch
-> Mod FlagFields KeyHideSwitch -> Parser KeyHideSwitch
forall a. a -> Mod FlagFields a -> Parser a
OA.flag'
          KeyHideSwitch
KeyHideOn
          ( [Mod FlagFields KeyHideSwitch] -> Mod FlagFields KeyHideSwitch
forall a. Monoid a => [a] -> a
mconcat
              [ String -> Mod FlagFields KeyHideSwitch
forall (f :: Type -> Type) a. HasName f => String -> Mod f a
OA.long String
"common-log-key-hide",
                String -> Mod FlagFields KeyHideSwitch
forall (f :: Type -> Type) a. String -> Mod f a
Utils.mkHelp String
helpTxt
              ]
          )
    helpTxt :: String
helpTxt =
      [String] -> String
forall a. Monoid a => [a] -> a
mconcat
        [ String
"By default, we display the key name from the legend over the ",
          String
"actual command that was run, if the former exists. This flag ",
          String
"instead shows the literal command. Commands without keys are ",
          String
"unaffected."
        ]