{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards   #-}

-- | Types and functions related to Stack's @eval@ command.

module Stack.Eval
  ( EvalOpts (..)
  , evalCmd
  ) where

import           Stack.Exec
                   ( ExecOpts (..), ExecOptsExtra, SpecialExecCmd (..)
                   , execCmd
                   )
import           Stack.Prelude
import           Stack.Types.Runner ( Runner )

-- Type representing command line options for the @stack eval@ command.

data EvalOpts = EvalOpts
  { EvalOpts -> String
evalArg :: !String
  , EvalOpts -> ExecOptsExtra
evalExtra :: !ExecOptsExtra
  }
  deriving Int -> EvalOpts -> ShowS
[EvalOpts] -> ShowS
EvalOpts -> String
(Int -> EvalOpts -> ShowS)
-> (EvalOpts -> String) -> ([EvalOpts] -> ShowS) -> Show EvalOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EvalOpts -> ShowS
showsPrec :: Int -> EvalOpts -> ShowS
$cshow :: EvalOpts -> String
show :: EvalOpts -> String
$cshowList :: [EvalOpts] -> ShowS
showList :: [EvalOpts] -> ShowS
Show

-- | Function underlying the @stack eval@ command. Evaluate some Haskell code

-- inline.

evalCmd :: EvalOpts -> RIO Runner ()
evalCmd :: EvalOpts -> RIO Runner ()
evalCmd EvalOpts {String
ExecOptsExtra
evalArg :: EvalOpts -> String
evalExtra :: EvalOpts -> ExecOptsExtra
evalArg :: String
evalExtra :: ExecOptsExtra
..} = ExecOpts -> RIO Runner ()
execCmd ExecOpts
execOpts
 where
  execOpts :: ExecOpts
execOpts =
    ExecOpts { eoCmd :: SpecialExecCmd
eoCmd = SpecialExecCmd
ExecGhc
             , eoArgs :: [String]
eoArgs = [String
"-e", String
evalArg]
             , eoExtra :: ExecOptsExtra
eoExtra = ExecOptsExtra
evalExtra
             }