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

-- | Functions to parse Stack's \'global\' command line arguments.

module Stack.Options.GlobalParser
  ( globalOptsFromMonoid
  , globalOptsParser
  ) where

import           Options.Applicative
                   ( Parser, ReadM, auto, completer, help, hidden, internal
                   , long, metavar, option, strOption, value
                   )
import           Options.Applicative.Builder.Extra
                   ( fileExtCompleter, firstBoolFlagsFalse
                   , firstBoolFlagsNoDefault, firstBoolFlagsTrue, optionalFirst
                   )
import           Options.Applicative.Types ( readerAsk )
import           Path.IO ( getCurrentDir, resolveDir', resolveFile' )
import qualified Stack.Docker as Docker
import           Stack.Prelude
import           Stack.Options.ConfigParser ( configOptsParser )
import           Stack.Options.LogLevelParser ( logLevelOptsParser )
import           Stack.Options.ResolverParser
                   ( abstractResolverOptsParser, compilerOptsParser )
import           Stack.Options.Utils ( GlobalOptsContext (..), hideMods )
import           Stack.Types.GlobalOpts ( GlobalOpts (..) )
import           Stack.Types.GlobalOptsMonoid ( GlobalOptsMonoid (..) )
import           Stack.Types.LockFileBehavior
                   ( LockFileBehavior (..), readLockFileBehavior )
import           Stack.Types.StackYamlLoc ( StackYamlLoc (..) )
import           Stack.Types.Docker ( dockerEntrypointArgName )

-- | Parser for global command-line options.

globalOptsParser ::
     FilePath
  -> GlobalOptsContext
  -> Parser GlobalOptsMonoid
globalOptsParser :: String -> GlobalOptsContext -> Parser GlobalOptsMonoid
globalOptsParser String
currentDir GlobalOptsContext
kind = First String
-> First DockerEntrypoint
-> First LogLevel
-> FirstTrue
-> FirstFalse
-> FirstFalse
-> ConfigMonoid
-> First (Unresolved AbstractResolver)
-> First String
-> First WantedCompiler
-> First Bool
-> StylesUpdate
-> First Int
-> First String
-> First LockFileBehavior
-> GlobalOptsMonoid
GlobalOptsMonoid
  (First String
 -> First DockerEntrypoint
 -> First LogLevel
 -> FirstTrue
 -> FirstFalse
 -> FirstFalse
 -> ConfigMonoid
 -> First (Unresolved AbstractResolver)
 -> First String
 -> First WantedCompiler
 -> First Bool
 -> StylesUpdate
 -> First Int
 -> First String
 -> First LockFileBehavior
 -> GlobalOptsMonoid)
-> Parser (First String)
-> Parser
     (First DockerEntrypoint
      -> First LogLevel
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser String -> Parser (First String)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
Docker.reExecArgName
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall (f :: * -> *) a. Mod f a
hidden
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall (f :: * -> *) a. Mod f a
internal
        ))
  Parser
  (First DockerEntrypoint
   -> First LogLevel
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First DockerEntrypoint)
-> Parser
     (First LogLevel
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser DockerEntrypoint -> Parser (First DockerEntrypoint)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM DockerEntrypoint
-> Mod OptionFields DockerEntrypoint -> Parser DockerEntrypoint
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM DockerEntrypoint
forall a. Read a => ReadM a
auto
        (  String -> Mod OptionFields DockerEntrypoint
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
dockerEntrypointArgName
        Mod OptionFields DockerEntrypoint
-> Mod OptionFields DockerEntrypoint
-> Mod OptionFields DockerEntrypoint
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields DockerEntrypoint
forall (f :: * -> *) a. Mod f a
hidden
        Mod OptionFields DockerEntrypoint
-> Mod OptionFields DockerEntrypoint
-> Mod OptionFields DockerEntrypoint
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields DockerEntrypoint
forall (f :: * -> *) a. Mod f a
internal
        ))
  Parser
  (First LogLevel
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First LogLevel)
-> Parser
     (FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe LogLevel -> First LogLevel
forall a. Maybe a -> First a
First (Maybe LogLevel -> First LogLevel)
-> Parser (Maybe LogLevel) -> Parser (First LogLevel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Parser (Maybe LogLevel)
logLevelOptsParser Bool
hide0)
  Parser
  (FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser FirstTrue
-> Parser
     (FirstFalse
      -> FirstFalse
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstTrue -> Parser FirstTrue
firstBoolFlagsTrue
        String
"time-in-log"
        String
"inclusion of timings in logs, for the purposes of using diff with \
        \logs."
        Mod FlagFields FirstTrue
forall (f :: * -> *) a. Mod f a
hide
  Parser
  (FirstFalse
   -> FirstFalse
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser FirstFalse
-> Parser
     (FirstFalse
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
        String
"rsl-in-log"
        String
"inclusion of raw snapshot layer (rsl) in logs."
        Mod FlagFields FirstFalse
forall (f :: * -> *) a. Mod f a
hide
  Parser
  (FirstFalse
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser FirstFalse
-> Parser
     (ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
        String
"plan-in-log"
        String
"inclusion of information about build plan construction in logs."
        Mod FlagFields FirstFalse
forall (f :: * -> *) a. Mod f a
hide
  Parser
  (ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser ConfigMonoid
-> Parser
     (First (Unresolved AbstractResolver)
      -> First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser String
currentDir GlobalOptsContext
kind
  Parser
  (First (Unresolved AbstractResolver)
   -> First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First (Unresolved AbstractResolver))
-> Parser
     (First String
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Unresolved AbstractResolver)
-> Parser (First (Unresolved AbstractResolver))
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Parser (Unresolved AbstractResolver)
abstractResolverOptsParser Bool
hide0)
  Parser
  (First String
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First String)
-> Parser
     (First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> First String -> Parser (First String)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe String -> First String
forall a. Maybe a -> First a
First Maybe String
forall a. Maybe a
Nothing)
  Parser
  (First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First WantedCompiler)
-> Parser
     (First Bool
      -> StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser WantedCompiler -> Parser (First WantedCompiler)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Parser WantedCompiler
compilerOptsParser Bool
hide0)
      -- resolver root is only set via the script command

  Parser
  (First Bool
   -> StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First Bool)
-> Parser
     (StylesUpdate
      -> First Int
      -> First String
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String
-> String -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
        String
"terminal"
        String
"overriding terminal detection in the case of running in a false \
        \terminal."
        Mod FlagFields (Maybe Bool)
forall (f :: * -> *) a. Mod f a
hide
  Parser
  (StylesUpdate
   -> First Int
   -> First String
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser StylesUpdate
-> Parser
     (First Int
      -> First String -> First LockFileBehavior -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReadM StylesUpdate
-> Mod OptionFields StylesUpdate -> Parser StylesUpdate
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM StylesUpdate
readStyles
        (  String -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"stack-colors"
        Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"stack-colours"
        Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"STYLES"
        Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<> StylesUpdate -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value StylesUpdate
forall a. Monoid a => a
mempty
        Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. String -> Mod f a
help String
"Specify Stack's output styles; STYLES is a colon-delimited \
                \sequence of key=value, where 'key' is a style name and 'value' \
                \is a semicolon-delimited list of 'ANSI' SGR (Select Graphic \
                \Rendition) control codes (in decimal). Use 'stack ls \
                \stack-colors --basic' to see the current sequence. In shells \
                \where a semicolon is a command separator, enclose STYLES in \
                \quotes."
        Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. Mod f a
hide
        )
  Parser
  (First Int
   -> First String -> First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First Int)
-> Parser
     (First String -> First LockFileBehavior -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int -> Parser (First Int)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM Int -> Mod OptionFields Int -> Parser Int
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Int
forall a. Read a => ReadM a
auto
        (  String -> Mod OptionFields Int
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"terminal-width"
        Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Int
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"INT"
        Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Int
forall (f :: * -> *) a. String -> Mod f a
help String
"Specify the width of the terminal, used for pretty-print \
                \messages."
        Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields Int
forall (f :: * -> *) a. Mod f a
hide
        ))
  Parser (First String -> First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First String)
-> Parser (First LockFileBehavior -> GlobalOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (First String)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"stack-yaml"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"STACK-YAML"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields String
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([String] -> Completer
fileExtCompleter [String
".yaml"])
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Override project stack.yaml file (overrides any STACK_YAML \
                \environment variable)."
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall (f :: * -> *) a. Mod f a
hide
        ))
  Parser (First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First LockFileBehavior) -> Parser GlobalOptsMonoid
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LockFileBehavior -> Parser (First LockFileBehavior)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM LockFileBehavior
-> Mod OptionFields LockFileBehavior -> Parser LockFileBehavior
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM LockFileBehavior
readLockFileBehavior
        (  String -> Mod OptionFields LockFileBehavior
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"lock-file"
        Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields LockFileBehavior
forall (f :: * -> *) a. String -> Mod f a
help String
"Specify how to interact with lock files. (default: if \
                \resolver is overridden: read-only; otherwise: read/write)"
        Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields LockFileBehavior
forall (f :: * -> *) a. Mod f a
hide
        ))
 where
  hide :: Mod f a
hide = Bool -> Mod f a
forall (f :: * -> *) a. Bool -> Mod f a
hideMods Bool
hide0
  hide0 :: Bool
hide0 = GlobalOptsContext
kind GlobalOptsContext -> GlobalOptsContext -> Bool
forall a. Eq a => a -> a -> Bool
/= GlobalOptsContext
OuterGlobalOpts

-- | Create GlobalOpts from GlobalOptsMonoid.

globalOptsFromMonoid ::
     MonadIO m
  => Bool
  -> GlobalOptsMonoid
  -> m GlobalOpts
globalOptsFromMonoid :: forall (m :: * -> *).
MonadIO m =>
Bool -> GlobalOptsMonoid -> m GlobalOpts
globalOptsFromMonoid Bool
defaultTerminal GlobalOptsMonoid{First Bool
First Int
First String
First WantedCompiler
First (Unresolved AbstractResolver)
First LogLevel
First DockerEntrypoint
First LockFileBehavior
StylesUpdate
FirstFalse
FirstTrue
ConfigMonoid
globalMonoidReExecVersion :: First String
globalMonoidDockerEntrypoint :: First DockerEntrypoint
globalMonoidLogLevel :: First LogLevel
globalMonoidTimeInLog :: FirstTrue
globalMonoidRSLInLog :: FirstFalse
globalMonoidPlanInLog :: FirstFalse
globalMonoidConfigMonoid :: ConfigMonoid
globalMonoidResolver :: First (Unresolved AbstractResolver)
globalMonoidResolverRoot :: First String
globalMonoidCompiler :: First WantedCompiler
globalMonoidTerminal :: First Bool
globalMonoidStyles :: StylesUpdate
globalMonoidTermWidth :: First Int
globalMonoidStackYaml :: First String
globalMonoidLockFileBehavior :: First LockFileBehavior
globalMonoidReExecVersion :: GlobalOptsMonoid -> First String
globalMonoidDockerEntrypoint :: GlobalOptsMonoid -> First DockerEntrypoint
globalMonoidLogLevel :: GlobalOptsMonoid -> First LogLevel
globalMonoidTimeInLog :: GlobalOptsMonoid -> FirstTrue
globalMonoidRSLInLog :: GlobalOptsMonoid -> FirstFalse
globalMonoidPlanInLog :: GlobalOptsMonoid -> FirstFalse
globalMonoidConfigMonoid :: GlobalOptsMonoid -> ConfigMonoid
globalMonoidResolver :: GlobalOptsMonoid -> First (Unresolved AbstractResolver)
globalMonoidResolverRoot :: GlobalOptsMonoid -> First String
globalMonoidCompiler :: GlobalOptsMonoid -> First WantedCompiler
globalMonoidTerminal :: GlobalOptsMonoid -> First Bool
globalMonoidStyles :: GlobalOptsMonoid -> StylesUpdate
globalMonoidTermWidth :: GlobalOptsMonoid -> First Int
globalMonoidStackYaml :: GlobalOptsMonoid -> First String
globalMonoidLockFileBehavior :: GlobalOptsMonoid -> First LockFileBehavior
..} = do
  Maybe AbstractResolver
resolver <- Maybe (Unresolved AbstractResolver)
-> (Unresolved AbstractResolver -> m AbstractResolver)
-> m (Maybe AbstractResolver)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for (First (Unresolved AbstractResolver)
-> Maybe (Unresolved AbstractResolver)
forall a. First a -> Maybe a
getFirst First (Unresolved AbstractResolver)
globalMonoidResolver) ((Unresolved AbstractResolver -> m AbstractResolver)
 -> m (Maybe AbstractResolver))
-> (Unresolved AbstractResolver -> m AbstractResolver)
-> m (Maybe AbstractResolver)
forall a b. (a -> b) -> a -> b
$ \Unresolved AbstractResolver
ur -> do
    Path Abs Dir
root <-
      case First String
globalMonoidResolverRoot of
        First Maybe String
Nothing -> m (Path Abs Dir)
forall (m :: * -> *). MonadIO m => m (Path Abs Dir)
getCurrentDir
        First (Just String
dir) -> String -> m (Path Abs Dir)
forall (m :: * -> *). MonadIO m => String -> m (Path Abs Dir)
resolveDir' String
dir
    Maybe (Path Abs Dir)
-> Unresolved AbstractResolver -> m AbstractResolver
forall (m :: * -> *) a.
MonadIO m =>
Maybe (Path Abs Dir) -> Unresolved a -> m a
resolvePaths (Path Abs Dir -> Maybe (Path Abs Dir)
forall a. a -> Maybe a
Just Path Abs Dir
root) Unresolved AbstractResolver
ur
  StackYamlLoc
stackYaml <-
    case First String -> Maybe String
forall a. First a -> Maybe a
getFirst First String
globalMonoidStackYaml of
      Maybe String
Nothing -> StackYamlLoc -> m StackYamlLoc
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StackYamlLoc
SYLDefault
      Just String
fp -> Path Abs File -> StackYamlLoc
SYLOverride (Path Abs File -> StackYamlLoc)
-> m (Path Abs File) -> m StackYamlLoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m (Path Abs File)
forall (m :: * -> *). MonadIO m => String -> m (Path Abs File)
resolveFile' String
fp
  GlobalOpts -> m GlobalOpts
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GlobalOpts
    { globalReExecVersion :: Maybe String
globalReExecVersion = First String -> Maybe String
forall a. First a -> Maybe a
getFirst First String
globalMonoidReExecVersion
    , globalDockerEntrypoint :: Maybe DockerEntrypoint
globalDockerEntrypoint = First DockerEntrypoint -> Maybe DockerEntrypoint
forall a. First a -> Maybe a
getFirst First DockerEntrypoint
globalMonoidDockerEntrypoint
    , globalLogLevel :: LogLevel
globalLogLevel = LogLevel -> First LogLevel -> LogLevel
forall a. a -> First a -> a
fromFirst LogLevel
defaultLogLevel First LogLevel
globalMonoidLogLevel
    , globalTimeInLog :: Bool
globalTimeInLog = FirstTrue -> Bool
fromFirstTrue FirstTrue
globalMonoidTimeInLog
    , globalRSLInLog :: Bool
globalRSLInLog = FirstFalse -> Bool
fromFirstFalse FirstFalse
globalMonoidRSLInLog
    , globalPlanInLog :: Bool
globalPlanInLog = FirstFalse -> Bool
fromFirstFalse FirstFalse
globalMonoidPlanInLog
    , globalConfigMonoid :: ConfigMonoid
globalConfigMonoid = ConfigMonoid
globalMonoidConfigMonoid
    , globalResolver :: Maybe AbstractResolver
globalResolver = Maybe AbstractResolver
resolver
    , globalCompiler :: Maybe WantedCompiler
globalCompiler = First WantedCompiler -> Maybe WantedCompiler
forall a. First a -> Maybe a
getFirst First WantedCompiler
globalMonoidCompiler
    , globalTerminal :: Bool
globalTerminal = Bool -> First Bool -> Bool
forall a. a -> First a -> a
fromFirst Bool
defaultTerminal First Bool
globalMonoidTerminal
    , globalStylesUpdate :: StylesUpdate
globalStylesUpdate = StylesUpdate
globalMonoidStyles
    , globalTermWidth :: Maybe Int
globalTermWidth = First Int -> Maybe Int
forall a. First a -> Maybe a
getFirst First Int
globalMonoidTermWidth
    , globalStackYaml :: StackYamlLoc
globalStackYaml = StackYamlLoc
stackYaml
    , globalLockFileBehavior :: LockFileBehavior
globalLockFileBehavior =
        let defLFB :: LockFileBehavior
defLFB =
              case First (Unresolved AbstractResolver)
-> Maybe (Unresolved AbstractResolver)
forall a. First a -> Maybe a
getFirst First (Unresolved AbstractResolver)
globalMonoidResolver of
                Maybe (Unresolved AbstractResolver)
Nothing -> LockFileBehavior
LFBReadWrite
                Maybe (Unresolved AbstractResolver)
_ -> LockFileBehavior
LFBReadOnly
        in  LockFileBehavior -> First LockFileBehavior -> LockFileBehavior
forall a. a -> First a -> a
fromFirst LockFileBehavior
defLFB First LockFileBehavior
globalMonoidLockFileBehavior
    }

-- | Default logging level should be something useful but not crazy.

defaultLogLevel :: LogLevel
defaultLogLevel :: LogLevel
defaultLogLevel = LogLevel
LevelInfo

readStyles :: ReadM StylesUpdate
readStyles :: ReadM StylesUpdate
readStyles = String -> StylesUpdate
parseStylesUpdateFromString (String -> StylesUpdate) -> ReadM String -> ReadM StylesUpdate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM String
readerAsk