module Stackctl.ColorOption
  ( ColorOption (..)
  , HasColorOption (..)
  , colorOption
  ) where

import Stackctl.Prelude

import Blammo.Logging.LogSettings
import Data.Semigroup (Last (..))
import Options.Applicative

newtype ColorOption = ColorOption
  { ColorOption -> LogColor
unColorOption :: LogColor
  }
  deriving (NonEmpty ColorOption -> ColorOption
ColorOption -> ColorOption -> ColorOption
forall b. Integral b => b -> ColorOption -> ColorOption
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> ColorOption -> ColorOption
$cstimes :: forall b. Integral b => b -> ColorOption -> ColorOption
sconcat :: NonEmpty ColorOption -> ColorOption
$csconcat :: NonEmpty ColorOption -> ColorOption
<> :: ColorOption -> ColorOption -> ColorOption
$c<> :: ColorOption -> ColorOption -> ColorOption
Semigroup) via Last ColorOption

class HasColorOption env where
  colorOptionL :: Lens' env (Maybe ColorOption)

colorOption :: Parser ColorOption
colorOption :: Parser ColorOption
colorOption =
  forall a. ReadM a -> Mod OptionFields a -> Parser a
option (forall a. (String -> Either String a) -> ReadM a
eitherReader forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LogColor -> ColorOption
ColorOption forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Either String LogColor
readLogColor)
    forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
      [forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"color", forall (f :: * -> *) a. String -> Mod f a
help String
"When to colorize output", forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"auto|always|never"]