module Stackctl.Spec.List
  ( ListOptions (..)
  , parseListOptions
  , runList
  ) where

import Stackctl.Prelude

import Blammo.Logging.Logger (pushLoggerLn)
import Options.Applicative
import Stackctl.AWS
import Stackctl.AWS.Scope
import Stackctl.Colors
import Stackctl.Config (HasConfig)
import Stackctl.DirectoryOption (HasDirectoryOption (..))
import Stackctl.FilterOption (HasFilterOption)
import Stackctl.Spec.Discover
import Stackctl.StackSpec

data ListOptions = ListOptions

-- brittany-disable-next-binding

parseListOptions :: Parser ListOptions
parseListOptions :: Parser ListOptions
parseListOptions = forall (f :: * -> *) a. Applicative f => a -> f a
pure ListOptions
ListOptions

runList
  :: ( MonadUnliftIO m
     , MonadMask m
     , MonadResource m
     , MonadLogger m
     , MonadReader env m
     , HasAwsScope env
     , HasAwsEnv env
     , HasLogger env
     , HasConfig env
     , HasDirectoryOption env
     , HasFilterOption env
     )
  => ListOptions
  -> m ()
runList :: forall (m :: * -> *) env.
(MonadUnliftIO m, MonadMask m, MonadResource m, MonadLogger m,
 MonadReader env m, HasAwsScope env, HasAwsEnv env, HasLogger env,
 HasConfig env, HasDirectoryOption env, HasFilterOption env) =>
ListOptions -> m ()
runList ListOptions
_ = do
  Colors {Text -> Text
gray :: Colors -> Text -> Text
black :: Colors -> Text -> Text
cyan :: Colors -> Text -> Text
magenta :: Colors -> Text -> Text
blue :: Colors -> Text -> Text
yellow :: Colors -> Text -> Text
green :: Colors -> Text -> Text
red :: Colors -> Text -> Text
bold :: Colors -> Text -> Text
dim :: Colors -> Text -> Text
dim :: Text -> Text
bold :: Text -> Text
red :: Text -> Text
green :: Text -> Text
yellow :: Text -> Text
blue :: Text -> Text
magenta :: Text -> Text
cyan :: Text -> Text
black :: Text -> Text
gray :: Text -> Text
..} <- forall env (m :: * -> *).
(MonadReader env m, HasLogger env) =>
m Colors
getColorsLogger

  forall (m :: * -> *) env.
(MonadMask m, MonadResource m, MonadLogger m, MonadReader env m,
 HasAwsScope env, HasConfig env, HasDirectoryOption env,
 HasFilterOption env) =>
(StackSpec -> m ()) -> m ()
forEachSpec_ forall a b. (a -> b) -> a -> b
$ \StackSpec
spec -> do
    let
      path :: FilePath
path = StackSpec -> FilePath
stackSpecFilePath StackSpec
spec
      name :: StackName
name = StackSpec -> StackName
stackSpecStackName StackSpec
spec

    Bool
exists <- forall a. Maybe a -> Bool
isJust forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) env.
(MonadUnliftIO m, MonadResource m, MonadReader env m,
 HasAwsEnv env) =>
StackName -> m (Maybe Stack)
awsCloudFormationDescribeStackMaybe StackName
name

    let
      formatted :: Text
      formatted :: Text
formatted =
        Text
"  "
          forall a. Semigroup a => a -> a -> a
<> (if Bool
exists then Text -> Text
green Text
"✓ " else Text -> Text
yellow Text
"✗ ")
          forall a. Semigroup a => a -> a -> a
<> Text -> Text
cyan (StackName -> Text
unStackName StackName
name)
          forall a. Semigroup a => a -> a -> a
<> Text
" => "
          forall a. Semigroup a => a -> a -> a
<> Text -> Text
magenta (FilePath -> Text
pack FilePath
path)

    forall (m :: * -> *) env.
(MonadIO m, MonadReader env m, HasLogger env) =>
Text -> m ()
pushLoggerLn Text
formatted