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

module Stack.Options.GlobalParser where

import           Options.Applicative
import           Options.Applicative.Builder.Extra
import           Path.IO (getCurrentDir, resolveDir', resolveFile')
import qualified Stack.Docker                      as Docker
import           Stack.Init
import           Stack.Prelude
import           Stack.Options.ConfigParser
import           Stack.Options.LogLevelParser
import           Stack.Options.ResolverParser
import           Stack.Options.Utils
import           Stack.Types.Config
import           Stack.Types.Docker

-- | Parser for global command-line options.
globalOptsParser :: FilePath -> GlobalOptsContext -> Maybe LogLevel -> Parser GlobalOptsMonoid
globalOptsParser :: FilePath
-> GlobalOptsContext -> Maybe LogLevel -> Parser GlobalOptsMonoid
globalOptsParser FilePath
currentDir GlobalOptsContext
kind Maybe LogLevel
defLogLevel =
    First FilePath
-> First DockerEntrypoint
-> First LogLevel
-> FirstTrue
-> ConfigMonoid
-> First (Unresolved AbstractResolver)
-> First FilePath
-> First WantedCompiler
-> First Bool
-> StylesUpdate
-> First Int
-> First FilePath
-> First LockFileBehavior
-> GlobalOptsMonoid
GlobalOptsMonoid (First FilePath
 -> First DockerEntrypoint
 -> First LogLevel
 -> FirstTrue
 -> ConfigMonoid
 -> First (Unresolved AbstractResolver)
 -> First FilePath
 -> First WantedCompiler
 -> First Bool
 -> StylesUpdate
 -> First Int
 -> First FilePath
 -> First LockFileBehavior
 -> GlobalOptsMonoid)
-> Parser (First FilePath)
-> Parser
     (First DockerEntrypoint
      -> First LogLevel
      -> FirstTrue
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    Parser FilePath -> Parser (First FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
Docker.reExecArgName Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields FilePath
forall (f :: * -> *) a. Mod f a
hidden Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields FilePath
forall (f :: * -> *) a. Mod f a
internal)) Parser
  (First DockerEntrypoint
   -> First LogLevel
   -> FirstTrue
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First DockerEntrypoint)
-> Parser
     (First LogLevel
      -> FirstTrue
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
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 (FilePath -> Mod OptionFields DockerEntrypoint
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
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
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First LogLevel)
-> Parser
     (FirstTrue
      -> ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
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 -> Maybe LogLevel -> Parser (Maybe LogLevel)
logLevelOptsParser Bool
hide0 Maybe LogLevel
defLogLevel) Parser
  (FirstTrue
   -> ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser FirstTrue
-> Parser
     (ConfigMonoid
      -> First (Unresolved AbstractResolver)
      -> First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
    FilePath
-> FilePath -> Mod FlagFields FirstTrue -> Parser FirstTrue
firstBoolFlagsTrue
        FilePath
"time-in-log"
        FilePath
"inclusion of timings in logs, for the purposes of using diff with logs"
        Mod FlagFields FirstTrue
forall (f :: * -> *) a. Mod f a
hide Parser
  (ConfigMonoid
   -> First (Unresolved AbstractResolver)
   -> First FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser ConfigMonoid
-> Parser
     (First (Unresolved AbstractResolver)
      -> First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
    FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser FilePath
currentDir GlobalOptsContext
kind Parser
  (First (Unresolved AbstractResolver)
   -> First FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First (Unresolved AbstractResolver))
-> Parser
     (First FilePath
      -> First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
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 FilePath
   -> First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First FilePath)
-> Parser
     (First WantedCompiler
      -> First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
    First FilePath -> Parser (First FilePath)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe FilePath -> First FilePath
forall a. Maybe a -> First a
First Maybe FilePath
forall a. Maybe a
Nothing) Parser
  (First WantedCompiler
   -> First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First WantedCompiler)
-> Parser
     (First Bool
      -> StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> -- resolver root is only set via the script command
    Parser WantedCompiler -> Parser (First WantedCompiler)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Parser WantedCompiler
compilerOptsParser Bool
hide0) Parser
  (First Bool
   -> StylesUpdate
   -> First Int
   -> First FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser (First Bool)
-> Parser
     (StylesUpdate
      -> First Int
      -> First FilePath
      -> First LockFileBehavior
      -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
    FilePath
-> FilePath -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
        FilePath
"terminal"
        FilePath
"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 FilePath
   -> First LockFileBehavior
   -> GlobalOptsMonoid)
-> Parser StylesUpdate
-> Parser
     (First Int
      -> First FilePath -> First LockFileBehavior -> GlobalOptsMonoid)
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
         (FilePath -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"stack-colors" Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<>
          FilePath -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"stack-colours" Mod OptionFields StylesUpdate
-> Mod OptionFields StylesUpdate -> Mod OptionFields StylesUpdate
forall a. Semigroup a => a -> a -> a
<>
          FilePath -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"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
<>
          FilePath -> Mod OptionFields StylesUpdate
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"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 FilePath -> First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First Int)
-> Parser
     (First FilePath -> First LockFileBehavior -> GlobalOptsMonoid)
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
        (FilePath -> Mod OptionFields Int
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"terminal-width" Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<>
         FilePath -> Mod OptionFields Int
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"INT" Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<>
         FilePath -> Mod OptionFields Int
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"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 FilePath -> First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First FilePath)
-> Parser (First LockFileBehavior -> GlobalOptsMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
    Parser FilePath -> Parser (First FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst
        (Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
            (FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"stack-yaml" Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<>
             FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"STACK-YAML" Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<>
             Completer -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([FilePath] -> Completer
fileExtCompleter [FilePath
".yaml"]) Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<>
             FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help (FilePath
"Override project stack.yaml file " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<>
                   FilePath
"(overrides any STACK_YAML environment variable)") Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<>
             Mod OptionFields FilePath
forall (f :: * -> *) a. Mod f a
hide)) Parser (First LockFileBehavior -> GlobalOptsMonoid)
-> Parser (First LockFileBehavior) -> Parser GlobalOptsMonoid
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
        (FilePath -> Mod OptionFields LockFileBehavior
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"lock-file" Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
-> Mod OptionFields LockFileBehavior
forall a. Semigroup a => a -> a -> a
<>
         FilePath -> Mod OptionFields LockFileBehavior
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Specify how to interact with lock files. Default: read/write. If resolver is overridden: read-only" 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 :: Bool -> GlobalOptsMonoid -> m GlobalOpts
globalOptsFromMonoid Bool
defaultTerminal GlobalOptsMonoid{First Bool
First Int
First FilePath
First (Unresolved AbstractResolver)
First WantedCompiler
First LogLevel
First DockerEntrypoint
First LockFileBehavior
StylesUpdate
FirstTrue
ConfigMonoid
globalMonoidLockFileBehavior :: GlobalOptsMonoid -> First LockFileBehavior
globalMonoidStackYaml :: GlobalOptsMonoid -> First FilePath
globalMonoidTermWidth :: GlobalOptsMonoid -> First Int
globalMonoidStyles :: GlobalOptsMonoid -> StylesUpdate
globalMonoidTerminal :: GlobalOptsMonoid -> First Bool
globalMonoidCompiler :: GlobalOptsMonoid -> First WantedCompiler
globalMonoidResolverRoot :: GlobalOptsMonoid -> First FilePath
globalMonoidResolver :: GlobalOptsMonoid -> First (Unresolved AbstractResolver)
globalMonoidConfigMonoid :: GlobalOptsMonoid -> ConfigMonoid
globalMonoidTimeInLog :: GlobalOptsMonoid -> FirstTrue
globalMonoidLogLevel :: GlobalOptsMonoid -> First LogLevel
globalMonoidDockerEntrypoint :: GlobalOptsMonoid -> First DockerEntrypoint
globalMonoidReExecVersion :: GlobalOptsMonoid -> First FilePath
globalMonoidLockFileBehavior :: First LockFileBehavior
globalMonoidStackYaml :: First FilePath
globalMonoidTermWidth :: First Int
globalMonoidStyles :: StylesUpdate
globalMonoidTerminal :: First Bool
globalMonoidCompiler :: First WantedCompiler
globalMonoidResolverRoot :: First FilePath
globalMonoidResolver :: First (Unresolved AbstractResolver)
globalMonoidConfigMonoid :: ConfigMonoid
globalMonoidTimeInLog :: FirstTrue
globalMonoidLogLevel :: First LogLevel
globalMonoidDockerEntrypoint :: First DockerEntrypoint
globalMonoidReExecVersion :: First FilePath
..} = 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 FilePath
globalMonoidResolverRoot of
        First Maybe FilePath
Nothing -> m (Path Abs Dir)
forall (m :: * -> *). MonadIO m => m (Path Abs Dir)
getCurrentDir
        First (Just FilePath
dir) -> FilePath -> m (Path Abs Dir)
forall (m :: * -> *). MonadIO m => FilePath -> m (Path Abs Dir)
resolveDir' FilePath
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 FilePath -> Maybe FilePath
forall a. First a -> Maybe a
getFirst First FilePath
globalMonoidStackYaml of
      Maybe FilePath
Nothing -> StackYamlLoc -> m StackYamlLoc
forall (f :: * -> *) a. Applicative f => a -> f a
pure StackYamlLoc
SYLDefault
      Just FilePath
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
<$> FilePath -> m (Path Abs File)
forall (m :: * -> *). MonadIO m => FilePath -> m (Path Abs File)
resolveFile' FilePath
fp
  GlobalOpts -> m GlobalOpts
forall (f :: * -> *) a. Applicative f => a -> f a
pure GlobalOpts :: Maybe FilePath
-> Maybe DockerEntrypoint
-> LogLevel
-> Bool
-> ConfigMonoid
-> Maybe AbstractResolver
-> Maybe WantedCompiler
-> Bool
-> StylesUpdate
-> Maybe Int
-> StackYamlLoc
-> LockFileBehavior
-> GlobalOpts
GlobalOpts
    { globalReExecVersion :: Maybe FilePath
globalReExecVersion = First FilePath -> Maybe FilePath
forall a. First a -> Maybe a
getFirst First FilePath
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
    , 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
    }

initOptsParser :: Parser InitOpts
initOptsParser :: Parser InitOpts
initOptsParser =
    [Text] -> Bool -> Bool -> Bool -> InitOpts
InitOpts ([Text] -> Bool -> Bool -> Bool -> InitOpts)
-> Parser [Text] -> Parser (Bool -> Bool -> Bool -> InitOpts)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Text]
searchDirs
             Parser (Bool -> Bool -> Bool -> InitOpts)
-> Parser Bool -> Parser (Bool -> Bool -> InitOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool
omitPackages
             Parser (Bool -> Bool -> InitOpts)
-> Parser Bool -> Parser (Bool -> InitOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool
overwrite Parser (Bool -> InitOpts) -> Parser Bool -> Parser InitOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> Bool) -> Parser Bool -> Parser Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not Parser Bool
ignoreSubDirs
  where
    searchDirs :: Parser [Text]
searchDirs =
      Parser Text -> Parser [Text]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod ArgumentFields Text -> Parser Text
textArgument
              (FilePath -> Mod ArgumentFields Text
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"DIR" Mod ArgumentFields Text
-> Mod ArgumentFields Text -> Mod ArgumentFields Text
forall a. Semigroup a => a -> a -> a
<>
               Completer -> Mod ArgumentFields Text
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer Completer
dirCompleter Mod ArgumentFields Text
-> Mod ArgumentFields Text -> Mod ArgumentFields Text
forall a. Semigroup a => a -> a -> a
<>
               FilePath -> Mod ArgumentFields Text
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Directories to include, default is current directory."))
    ignoreSubDirs :: Parser Bool
ignoreSubDirs = Mod FlagFields Bool -> Parser Bool
switch (FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"ignore-subdirs" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
                           FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Do not search for .cabal files in sub directories")
    overwrite :: Parser Bool
overwrite = Mod FlagFields Bool -> Parser Bool
switch (FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"force" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
                       FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Force overwriting an existing stack.yaml")
    omitPackages :: Parser Bool
omitPackages = Mod FlagFields Bool -> Parser Bool
switch (FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"omit-packages" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
                           FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Exclude conflicting or incompatible user packages")