Skip to content

Commit

Permalink
Disable ambiguous global '--resolver' option for 'stack init'
Browse files Browse the repository at this point in the history
fixes #1531
  • Loading branch information
borsboom committed Dec 29, 2015
1 parent c7038dd commit ed2c2c4
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 269 deletions.
28 changes: 21 additions & 7 deletions src/Stack/Options.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE OverloadedStrings,RecordWildCards #-}

module Stack.Options
(Command(..)
(BuildCommand(..)
,GlobalOptsContext(..)
,benchOptsParser
,buildOptsParser
,cleanOptsParser
Expand Down Expand Up @@ -58,14 +59,21 @@ import Stack.Types
import Stack.Types.TemplateName

-- | Command sum type for conditional arguments.
data Command
data BuildCommand
= Build
| Test
| Haddock
| Bench
| Install
deriving (Eq)

-- | Allows adjust global options depending on their context
data GlobalOptsContext
= OuterGlobalOpts -- | Global options before subcommand name
| InitCmdGlobalOpts -- | Global options following 'stack init'
| OtherCmdGlobalOpts -- | Global options following any other subcommand
deriving (Show, Eq)

-- | Parser for bench arguments.
benchOptsParser :: Parser BenchmarkOpts
benchOptsParser = BenchmarkOpts
Expand All @@ -77,7 +85,7 @@ benchOptsParser = BenchmarkOpts
help "Disable running of benchmarks. (Benchmarks will still be built.)")

-- | Parser for build arguments.
buildOptsParser :: Command
buildOptsParser :: BuildCommand
-> Parser BuildOpts
buildOptsParser cmd =
transform <$> trace <*> profile <*> options
Expand Down Expand Up @@ -622,14 +630,18 @@ execOptsExtraParser = eoPlainParser <|>
help "Use an unmodified environment (only useful with Docker)")

-- | Parser for global command-line options.
globalOptsParser :: Bool -> Maybe LogLevel -> Parser GlobalOptsMonoid
globalOptsParser hide0 defLogLevel =
globalOptsParser :: GlobalOptsContext -> Maybe LogLevel -> Parser GlobalOptsMonoid
globalOptsParser kind defLogLevel =
GlobalOptsMonoid <$>
optional (strOption (long Docker.reExecArgName <> hidden <> internal)) <*>
optional (option auto (long dockerEntrypointArgName <> hidden <> internal)) <*>
logLevelOptsParser hide0 defLogLevel <*>
configOptsParser hide0 <*>
optional (abstractResolverOptsParser hide0) <*>
(if kind == InitCmdGlobalOpts
-- The 'stack init' command has its own '--resolver' option, and having a global
-- one causes ambiguity, so disable it.
then pure Nothing
else optional (abstractResolverOptsParser hide0)) <*>
optional (compilerOptsParser hide0) <*>
maybeBoolFlags
"terminal"
Expand All @@ -640,7 +652,9 @@ globalOptsParser hide0 defLogLevel =
help ("Override project stack.yaml file " <>
"(overrides any STACK_YAML environment variable)") <>
hide))
where hide = hideMods hide0
where
hide = hideMods hide0
hide0 = kind /= OuterGlobalOpts

-- | Create GlobalOpts from GlobalOptsMonoid.
globalOptsFromMonoid :: Bool -> GlobalOptsMonoid -> GlobalOpts
Expand Down
1 change: 0 additions & 1 deletion src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,6 @@ getUtf8EnvVars
getUtf8EnvVars menv compilerVer = do
if getGhcVersion compilerVer >= $(mkVersion "7.10.3")
-- GHC_CHARENC supported by GHC >=7.10.3
--EKB XXX TEST
then return $ Map.singleton "GHC_CHARENC" "UTF-8"
else legacyLocale
where
Expand Down
Loading

0 comments on commit ed2c2c4

Please sign in to comment.