module Stackctl.VerboseOption
  ( Verbosity
  , verbositySetLogLevels
  , HasVerboseOption (..)
  , verboseOption
  ) where

import Stackctl.Prelude

import Blammo.Logging.LogSettings.LogLevels
import Options.Applicative

newtype Verbosity = Verbosity [()]
  deriving newtype (NonEmpty Verbosity -> Verbosity
Verbosity -> Verbosity -> Verbosity
forall b. Integral b => b -> Verbosity -> Verbosity
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> Verbosity -> Verbosity
$cstimes :: forall b. Integral b => b -> Verbosity -> Verbosity
sconcat :: NonEmpty Verbosity -> Verbosity
$csconcat :: NonEmpty Verbosity -> Verbosity
<> :: Verbosity -> Verbosity -> Verbosity
$c<> :: Verbosity -> Verbosity -> Verbosity
Semigroup, Semigroup Verbosity
Verbosity
[Verbosity] -> Verbosity
Verbosity -> Verbosity -> Verbosity
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [Verbosity] -> Verbosity
$cmconcat :: [Verbosity] -> Verbosity
mappend :: Verbosity -> Verbosity -> Verbosity
$cmappend :: Verbosity -> Verbosity -> Verbosity
mempty :: Verbosity
$cmempty :: Verbosity
Monoid)

verbositySetLogLevels :: Verbosity -> (LogSettings -> LogSettings)
verbositySetLogLevels :: Verbosity -> LogSettings -> LogSettings
verbositySetLogLevels (Verbosity [()]
bs) = case [()]
bs of
  [] -> forall a. a -> a
id
  [()
_] -> LogLevels -> LogSettings -> LogSettings
setLogSettingsLevels LogLevels
v
  [()
_, ()
_] -> LogLevels -> LogSettings -> LogSettings
setLogSettingsLevels LogLevels
vv
  [()]
_ -> LogLevels -> LogSettings -> LogSettings
setLogSettingsLevels LogLevels
vvv
 where
  v :: LogLevels
v = LogLevel -> [(LogSource, LogLevel)] -> LogLevels
newLogLevels LogLevel
LevelDebug [(LogSource
"Amazonka", LogLevel
LevelInfo)]
  vv :: LogLevels
vv = LogLevel -> [(LogSource, LogLevel)] -> LogLevels
newLogLevels LogLevel
LevelDebug []
  vvv :: LogLevels
vvv = LogLevel -> [(LogSource, LogLevel)] -> LogLevels
newLogLevels (LogSource -> LogLevel
LevelOther LogSource
"trace") []

class HasVerboseOption env where
  verboseOptionL :: Lens' env Verbosity

instance HasVerboseOption Verbosity where
  verboseOptionL :: Lens' Verbosity Verbosity
verboseOptionL = forall a. a -> a
id

verboseOption :: Parser Verbosity
verboseOption :: Parser Verbosity
verboseOption =
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [()] -> Verbosity
Verbosity
    forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Alternative f => f a -> f [a]
many
    forall a b. (a -> b) -> a -> b
$ forall a. a -> Mod FlagFields a -> Parser a
flag' ()
    forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
      [ forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'v'
      , forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"verbose"
      , forall (f :: * -> *) a. String -> Mod f a
help String
"Increase verbosity (can be passed multiple times)"
      ]