forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigCmd.hs
More file actions
67 lines (59 loc) · 2.11 KB
/
ConfigCmd.hs
File metadata and controls
67 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | Make changes to the stack yaml file
module Stack.ConfigCmd
(ConfigCmdSet(..)
,cfgCmdSet
,cfgCmdSetName
,cfgCmdName) where
import Control.Monad.Catch (MonadMask, throwM)
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.ByteString as S
import qualified Data.HashMap.Strict as HMap
import qualified Data.Yaml as Yaml
import Network.HTTP.Client.Conduit (HasHttpManager)
import Path
import Stack.BuildPlan
import Stack.Config (makeConcreteResolver)
import Stack.Types
data ConfigCmdSet = ConfigCmdSetResolver AbstractResolver
cfgCmdSet :: ( MonadIO m
, MonadBaseControl IO m
, MonadMask m
, MonadReader env m
, HasBuildConfig env
, HasHttpManager env
, HasGHCVariant env
, MonadLogger m)
=> ConfigCmdSet -> m ()
cfgCmdSet (ConfigCmdSetResolver newResolver) = do
stackYaml <- fmap bcStackYaml (asks getBuildConfig)
let stackYamlFp =
toFilePath stackYaml
-- We don't need to worry about checking for a valid yaml here
(projectYamlConfig :: Yaml.Object) <-
liftIO (Yaml.decodeFileEither stackYamlFp) >>=
either throwM return
-- TODO: custom snapshot support?
newResolverText <- fmap resolverName (makeConcreteResolver newResolver)
-- We checking here that the snapshot actually exists
snap <- parseSnapName newResolverText
_ <- loadMiniBuildPlan snap
let projectYamlConfig' =
HMap.insert
"resolver"
(Yaml.String newResolverText)
projectYamlConfig
liftIO
(S.writeFile
stackYamlFp
(Yaml.encode projectYamlConfig'))
return ()
cfgCmdName :: String
cfgCmdName = "config"
cfgCmdSetName :: String
cfgCmdSetName = "set"