{-# LANGUAGE NoImplicitPrelude     #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors      #-}
{-# LANGUAGE OverloadedRecordDot   #-}

-- | 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
arg :: !String
  , EvalOpts -> ExecOptsExtra
extra :: !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
eval = ExecOpts -> RIO Runner ()
execCmd ExecOpts
execOpts
 where
  execOpts :: ExecOpts
execOpts = ExecOpts
    { cmd :: SpecialExecCmd
cmd = SpecialExecCmd
ExecGhc
    , args :: [String]
args = [String
"-e", EvalOpts
eval.arg]
    , extra :: ExecOptsExtra
extra = EvalOpts
eval.extra
    }