{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Types.GhcOptions
  ( GhcOptions (..)
  ) where

import           Data.Attoparsec.Args ( EscapingMode (Escaping), parseArgs )
import qualified Data.Text as T
import           Pantry.Internal.AesonExtended ( FromJSON (..), withText )
import           Stack.Prelude

newtype GhcOptions = GhcOptions { GhcOptions -> [Text]
unGhcOptions :: [Text] }

instance FromJSON GhcOptions where
  parseJSON :: Value -> Parser GhcOptions
parseJSON = forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"GhcOptions" forall a b. (a -> b) -> a -> b
$ \Text
t ->
    case EscapingMode -> Text -> Either String [String]
parseArgs EscapingMode
Escaping Text
t of
      Left String
e -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e
      Right [String]
opts -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [Text] -> GhcOptions
GhcOptions forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack [String]
opts