{-# LANGUAGE NoImplicitPrelude #-}
module Stack.Options.ConfigParser where

import           Data.Char
import           Options.Applicative
import           Options.Applicative.Builder.Extra
import           Path
import           Stack.Constants
import           Stack.Options.BuildMonoidParser
import           Stack.Options.DockerParser
import           Stack.Options.GhcBuildParser
import           Stack.Options.GhcVariantParser
import           Stack.Options.NixParser
import           Stack.Options.Utils
import           Stack.Prelude
import           Stack.Types.Config
import qualified System.FilePath as FilePath

-- | Command-line arguments parser for configuration.
configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser currentDir :: FilePath
currentDir hide0 :: GlobalOptsContext
hide0 =
    (\stackRoot :: First (Path Abs Dir)
stackRoot workDir :: First (Path Rel Dir)
workDir buildOpts :: BuildOptsMonoid
buildOpts dockerOpts :: DockerOptsMonoid
dockerOpts nixOpts :: NixOptsMonoid
nixOpts systemGHC :: First Bool
systemGHC installGHC :: FirstTrue
installGHC arch :: First FilePath
arch
        ghcVariant :: First GHCVariant
ghcVariant ghcBuild :: First CompilerBuild
ghcBuild jobs :: First Int
jobs includes :: [FilePath]
includes libs :: [FilePath]
libs overrideGccPath :: First (Path Abs File)
overrideGccPath overrideHpack :: First FilePath
overrideHpack
        skipGHCCheck :: FirstFalse
skipGHCCheck skipMsys :: FirstFalse
skipMsys localBin :: First FilePath
localBin setupInfoLocations :: [FilePath]
setupInfoLocations modifyCodePage :: FirstTrue
modifyCodePage
        allowDifferentUser :: First Bool
allowDifferentUser dumpLogs :: First DumpLogs
dumpLogs colorWhen :: First ColorWhen
colorWhen -> ConfigMonoid
forall a. Monoid a => a
mempty
            { configMonoidStackRoot :: First (Path Abs Dir)
configMonoidStackRoot = First (Path Abs Dir)
stackRoot
            , configMonoidWorkDir :: First (Path Rel Dir)
configMonoidWorkDir = First (Path Rel Dir)
workDir
            , configMonoidBuildOpts :: BuildOptsMonoid
configMonoidBuildOpts = BuildOptsMonoid
buildOpts
            , configMonoidDockerOpts :: DockerOptsMonoid
configMonoidDockerOpts = DockerOptsMonoid
dockerOpts
            , configMonoidNixOpts :: NixOptsMonoid
configMonoidNixOpts = NixOptsMonoid
nixOpts
            , configMonoidSystemGHC :: First Bool
configMonoidSystemGHC = First Bool
systemGHC
            , configMonoidInstallGHC :: FirstTrue
configMonoidInstallGHC = FirstTrue
installGHC
            , configMonoidSkipGHCCheck :: FirstFalse
configMonoidSkipGHCCheck = FirstFalse
skipGHCCheck
            , configMonoidArch :: First FilePath
configMonoidArch = First FilePath
arch
            , configMonoidGHCVariant :: First GHCVariant
configMonoidGHCVariant = First GHCVariant
ghcVariant
            , configMonoidGHCBuild :: First CompilerBuild
configMonoidGHCBuild = First CompilerBuild
ghcBuild
            , configMonoidJobs :: First Int
configMonoidJobs = First Int
jobs
            , configMonoidExtraIncludeDirs :: [FilePath]
configMonoidExtraIncludeDirs = [FilePath]
includes
            , configMonoidExtraLibDirs :: [FilePath]
configMonoidExtraLibDirs = [FilePath]
libs
            , configMonoidOverrideGccPath :: First (Path Abs File)
configMonoidOverrideGccPath = First (Path Abs File)
overrideGccPath
            , configMonoidOverrideHpack :: First FilePath
configMonoidOverrideHpack = First FilePath
overrideHpack
            , configMonoidSkipMsys :: FirstFalse
configMonoidSkipMsys = FirstFalse
skipMsys
            , configMonoidLocalBinPath :: First FilePath
configMonoidLocalBinPath = First FilePath
localBin
            , configMonoidSetupInfoLocations :: [FilePath]
configMonoidSetupInfoLocations = [FilePath]
setupInfoLocations
            , configMonoidModifyCodePage :: FirstTrue
configMonoidModifyCodePage = FirstTrue
modifyCodePage
            , configMonoidAllowDifferentUser :: First Bool
configMonoidAllowDifferentUser = First Bool
allowDifferentUser
            , configMonoidDumpLogs :: First DumpLogs
configMonoidDumpLogs = First DumpLogs
dumpLogs
            , configMonoidColorWhen :: First ColorWhen
configMonoidColorWhen = First ColorWhen
colorWhen
            })
    (First (Path Abs Dir)
 -> First (Path Rel Dir)
 -> BuildOptsMonoid
 -> DockerOptsMonoid
 -> NixOptsMonoid
 -> First Bool
 -> FirstTrue
 -> First FilePath
 -> First GHCVariant
 -> First CompilerBuild
 -> First Int
 -> [FilePath]
 -> [FilePath]
 -> First (Path Abs File)
 -> First FilePath
 -> FirstFalse
 -> FirstFalse
 -> First FilePath
 -> [FilePath]
 -> FirstTrue
 -> First Bool
 -> First DumpLogs
 -> First ColorWhen
 -> ConfigMonoid)
-> Parser (First (Path Abs Dir))
-> Parser
     (First (Path Rel Dir)
      -> BuildOptsMonoid
      -> DockerOptsMonoid
      -> NixOptsMonoid
      -> First Bool
      -> FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Path Abs Dir) -> Parser (First (Path Abs Dir))
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields (Path Abs Dir) -> Parser (Path Abs Dir)
absDirOption
            ( FilePath -> Mod OptionFields (Path Abs Dir)
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
stackRootOptionName
            Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Abs Dir)
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar ((Char -> Char) -> FilePath -> FilePath
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper FilePath
stackRootOptionName)
            Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Abs Dir)
forall (f :: * -> *) a. FilePath -> Mod f a
help ("Absolute path to the global stack root directory " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
                     "(Overrides any STACK_ROOT environment variable)")
            Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
-> Mod OptionFields (Path Abs Dir)
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields (Path Abs Dir)
forall (f :: * -> *) a. Mod f a
hide
            ))
    Parser
  (First (Path Rel Dir)
   -> BuildOptsMonoid
   -> DockerOptsMonoid
   -> NixOptsMonoid
   -> First Bool
   -> FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First (Path Rel Dir))
-> Parser
     (BuildOptsMonoid
      -> DockerOptsMonoid
      -> NixOptsMonoid
      -> First Bool
      -> FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Path Rel Dir) -> Parser (First (Path Rel Dir))
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir) -> Parser (Path Rel Dir)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ((FilePath -> Either FilePath (Path Rel Dir))
-> ReadM (Path Rel Dir)
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((SomeException -> FilePath)
-> Either SomeException (Path Rel Dir)
-> Either FilePath (Path Rel Dir)
forall a1 a2 b. (a1 -> a2) -> Either a1 b -> Either a2 b
mapLeft SomeException -> FilePath
forall a. Show a => a -> FilePath
showWorkDirError (Either SomeException (Path Rel Dir)
 -> Either FilePath (Path Rel Dir))
-> (FilePath -> Either SomeException (Path Rel Dir))
-> FilePath
-> Either FilePath (Path Rel Dir)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Either SomeException (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel Dir)
parseRelDir))
            ( FilePath -> Mod OptionFields (Path Rel Dir)
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long "work-dir"
            Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Rel Dir)
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar "WORK-DIR"
            Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields (Path Rel Dir)
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer (PathCompleterOpts -> Completer
pathCompleterWith (PathCompleterOpts
defaultPathCompleterOpts { pcoAbsolute :: Bool
pcoAbsolute = Bool
False, pcoFileFilter :: FilePath -> Bool
pcoFileFilter = Bool -> FilePath -> Bool
forall a b. a -> b -> a
const Bool
False }))
            Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Rel Dir)
forall (f :: * -> *) a. FilePath -> Mod f a
help ("Relative path of work directory " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
                     "(Overrides any STACK_WORK environment variable, default is '.stack-work')")
            Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
-> Mod OptionFields (Path Rel Dir)
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields (Path Rel Dir)
forall (f :: * -> *) a. Mod f a
hide
            ))
    Parser
  (BuildOptsMonoid
   -> DockerOptsMonoid
   -> NixOptsMonoid
   -> First Bool
   -> FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser BuildOptsMonoid
-> Parser
     (DockerOptsMonoid
      -> NixOptsMonoid
      -> First Bool
      -> FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GlobalOptsContext -> Parser BuildOptsMonoid
buildOptsMonoidParser GlobalOptsContext
hide0
    Parser
  (DockerOptsMonoid
   -> NixOptsMonoid
   -> First Bool
   -> FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser DockerOptsMonoid
-> Parser
     (NixOptsMonoid
      -> First Bool
      -> FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser DockerOptsMonoid
dockerOptsParser Bool
True
    Parser
  (NixOptsMonoid
   -> First Bool
   -> FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser NixOptsMonoid
-> Parser
     (First Bool
      -> FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser NixOptsMonoid
nixOptsParser Bool
True
    Parser
  (First Bool
   -> FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First Bool)
-> Parser
     (FirstTrue
      -> First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
            "system-ghc"
            "using the system installed GHC (on the PATH) if it is available and its version matches. Disabled by default."
            Mod FlagFields (Maybe Bool)
forall (f :: * -> *) a. Mod f a
hide
    Parser
  (FirstTrue
   -> First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser FirstTrue
-> Parser
     (First FilePath
      -> First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields FirstTrue -> Parser FirstTrue
firstBoolFlagsTrue
            "install-ghc"
            "downloading and installing GHC if necessary (can be done manually with stack setup)"
            Mod FlagFields FirstTrue
forall (f :: * -> *) a. Mod f a
hide
    Parser
  (First FilePath
   -> First GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First FilePath)
-> Parser
     (First GHCVariant
      -> First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
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 "arch"
           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 "ARCH"
           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 "System architecture, e.g. i386, x86_64"
           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 GHCVariant
   -> First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First GHCVariant)
-> Parser
     (First CompilerBuild
      -> First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser GHCVariant -> Parser (First GHCVariant)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Parser GHCVariant
ghcVariantParser (GlobalOptsContext
hide0 GlobalOptsContext -> GlobalOptsContext -> Bool
forall a. Eq a => a -> a -> Bool
/= GlobalOptsContext
OuterGlobalOpts))
    Parser
  (First CompilerBuild
   -> First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First CompilerBuild)
-> Parser
     (First Int
      -> [FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser CompilerBuild -> Parser (First CompilerBuild)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Bool -> Parser CompilerBuild
ghcBuildParser (GlobalOptsContext
hide0 GlobalOptsContext -> GlobalOptsContext -> Bool
forall a. Eq a => a -> a -> Bool
/= GlobalOptsContext
OuterGlobalOpts))
    Parser
  (First Int
   -> [FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First Int)
-> Parser
     ([FilePath]
      -> [FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
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 "jobs"
           Mod OptionFields Int
-> Mod OptionFields Int -> Mod OptionFields Int
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Int
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short 'j'
           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 "JOBS"
           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 "Number of concurrent jobs to run"
           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
  ([FilePath]
   -> [FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser [FilePath]
-> Parser
     ([FilePath]
      -> First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath -> Parser [FilePath]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ((FilePath
currentDir FilePath -> FilePath -> FilePath
FilePath.</>) (FilePath -> FilePath) -> Parser FilePath -> Parser FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 "extra-include-dirs"
           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 "DIR"
           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 Completer
dirCompleter
           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 "Extra directories to check for C header files"
           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
  ([FilePath]
   -> First (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser [FilePath]
-> Parser
     (First (Path Abs File)
      -> First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath -> Parser [FilePath]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ((FilePath
currentDir FilePath -> FilePath -> FilePath
FilePath.</>) (FilePath -> FilePath) -> Parser FilePath -> Parser FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 "extra-lib-dirs"
           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 "DIR"
           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 Completer
dirCompleter
           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 "Extra directories to check for libraries"
           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 (Path Abs File)
   -> First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First (Path Abs File))
-> Parser
     (First FilePath
      -> FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Path Abs File) -> Parser (First (Path Abs File))
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Mod OptionFields (Path Abs File) -> Parser (Path Abs File)
absFileOption
             ( FilePath -> Mod OptionFields (Path Abs File)
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long "with-gcc"
            Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Abs File)
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar "PATH-TO-GCC"
            Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Path Abs File)
forall (f :: * -> *) a. FilePath -> Mod f a
help "Use gcc found at PATH-TO-GCC"
            Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
-> Mod OptionFields (Path Abs File)
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields (Path Abs File)
forall (f :: * -> *) a. Mod f a
hide
             ))
    Parser
  (First FilePath
   -> FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First FilePath)
-> Parser
     (FirstFalse
      -> FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
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 "with-hpack"
            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 "HPACK"
            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 "Use HPACK executable (overrides bundled Hpack)"
            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
  (FirstFalse
   -> FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser FirstFalse
-> Parser
     (FirstFalse
      -> First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
            "skip-ghc-check"
            "skipping the GHC version and architecture check"
            Mod FlagFields FirstFalse
forall (f :: * -> *) a. Mod f a
hide
    Parser
  (FirstFalse
   -> First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser FirstFalse
-> Parser
     (First FilePath
      -> [FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
            "skip-msys"
            "skipping the local MSYS installation (Windows only)"
            Mod FlagFields FirstFalse
forall (f :: * -> *) a. Mod f a
hide
    Parser
  (First FilePath
   -> [FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser (First FilePath)
-> Parser
     ([FilePath]
      -> FirstTrue
      -> First Bool
      -> First DumpLogs
      -> First ColorWhen
      -> ConfigMonoid)
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 ((FilePath
currentDir FilePath -> FilePath -> FilePath
FilePath.</>) (FilePath -> FilePath) -> Parser FilePath -> Parser FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 "local-bin-path"
            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 "DIR"
            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 Completer
dirCompleter
            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 "Install binaries to DIR"
            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
  ([FilePath]
   -> FirstTrue
   -> First Bool
   -> First DumpLogs
   -> First ColorWhen
   -> ConfigMonoid)
-> Parser [FilePath]
-> Parser
     (FirstTrue
      -> First Bool -> First DumpLogs -> First ColorWhen -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath -> Parser [FilePath]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (
        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 "setup-info-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 "Alternate URL or relative / absolute path for stack dependencies"
           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 "URL" ))
    Parser
  (FirstTrue
   -> First Bool -> First DumpLogs -> First ColorWhen -> ConfigMonoid)
-> Parser FirstTrue
-> Parser
     (First Bool -> First DumpLogs -> First ColorWhen -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields FirstTrue -> Parser FirstTrue
firstBoolFlagsTrue
            "modify-code-page"
            "setting the codepage to support UTF-8 (Windows only)"
            Mod FlagFields FirstTrue
forall (f :: * -> *) a. Mod f a
hide
    Parser
  (First Bool -> First DumpLogs -> First ColorWhen -> ConfigMonoid)
-> Parser (First Bool)
-> Parser (First DumpLogs -> First ColorWhen -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath
-> FilePath -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
            "allow-different-user"
            ("permission for users other than the owner of the stack root " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
                "directory to use a stack installation (POSIX only) " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
                "(default: true inside Docker, otherwise false)")
            Mod FlagFields (Maybe Bool)
forall (f :: * -> *) a. Mod f a
hide
    Parser (First DumpLogs -> First ColorWhen -> ConfigMonoid)
-> Parser (First DumpLogs)
-> Parser (First ColorWhen -> ConfigMonoid)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (First Bool -> First DumpLogs)
-> Parser (First Bool) -> Parser (First DumpLogs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap First Bool -> First DumpLogs
toDumpLogs
            (FilePath
-> FilePath -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
             "dump-logs"
             "dump the build output logs for local packages to the console (default: dump warning logs)"
             Mod FlagFields (Maybe Bool)
forall (f :: * -> *) a. Mod f a
hide)
    Parser (First ColorWhen -> ConfigMonoid)
-> Parser (First ColorWhen) -> Parser ConfigMonoid
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ColorWhen -> Parser (First ColorWhen)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM ColorWhen -> Mod OptionFields ColorWhen -> Parser ColorWhen
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM ColorWhen
readColorWhen
             ( FilePath -> Mod OptionFields ColorWhen
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long "color"
            Mod OptionFields ColorWhen
-> Mod OptionFields ColorWhen -> Mod OptionFields ColorWhen
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields ColorWhen
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long "colour"
            Mod OptionFields ColorWhen
-> Mod OptionFields ColorWhen -> Mod OptionFields ColorWhen
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields ColorWhen
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar "WHEN"
            Mod OptionFields ColorWhen
-> Mod OptionFields ColorWhen -> Mod OptionFields ColorWhen
forall a. Semigroup a => a -> a -> a
<> [FilePath] -> Mod OptionFields ColorWhen
forall (f :: * -> *) a. HasCompleter f => [FilePath] -> Mod f a
completeWith ["always", "never", "auto"]
            Mod OptionFields ColorWhen
-> Mod OptionFields ColorWhen -> Mod OptionFields ColorWhen
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields ColorWhen
forall (f :: * -> *) a. FilePath -> Mod f a
help "Specify when to use color in output; WHEN is 'always', \
                    \'never', or 'auto'. On Windows versions before Windows \
                    \10, for terminals that do not support color codes, the \
                    \default is 'never'; color may work on terminals that \
                    \support color codes"
            Mod OptionFields ColorWhen
-> Mod OptionFields ColorWhen -> Mod OptionFields ColorWhen
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields ColorWhen
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 (GlobalOptsContext
hide0 GlobalOptsContext -> GlobalOptsContext -> Bool
forall a. Eq a => a -> a -> Bool
/= GlobalOptsContext
OuterGlobalOpts)
    toDumpLogs :: First Bool -> First DumpLogs
toDumpLogs (First (Just True)) = Maybe DumpLogs -> First DumpLogs
forall a. Maybe a -> First a
First (DumpLogs -> Maybe DumpLogs
forall a. a -> Maybe a
Just DumpLogs
DumpAllLogs)
    toDumpLogs (First (Just False)) = Maybe DumpLogs -> First DumpLogs
forall a. Maybe a -> First a
First (DumpLogs -> Maybe DumpLogs
forall a. a -> Maybe a
Just DumpLogs
DumpNoLogs)
    toDumpLogs (First Nothing) = Maybe DumpLogs -> First DumpLogs
forall a. Maybe a -> First a
First Maybe DumpLogs
forall a. Maybe a
Nothing
    showWorkDirError :: a -> FilePath
showWorkDirError err :: a
err = a -> FilePath
forall a. Show a => a -> FilePath
show a
err FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
        "\nNote that --work-dir must be a relative child directory, because work-dirs outside of the package are not supported by Cabal." FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
        "\nSee https://github.com/commercialhaskell/stack/issues/2954"