-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1202 from commercialhaskell/115-set-resolver
Stack config add resolver command
- Loading branch information
Showing
5 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{-# 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, MonadThrow) | ||
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.Init | ||
import Stack.Types | ||
|
||
data ConfigCmdSet = ConfigCmdSetResolver AbstractResolver | ||
|
||
cfgCmdSet :: ( MonadIO m | ||
, MonadBaseControl IO m | ||
, MonadMask m | ||
, MonadReader env m | ||
, HasConfig env | ||
, HasBuildConfig env | ||
, HasHttpManager env | ||
, HasGHCVariant env | ||
, MonadThrow m | ||
, 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 | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters