1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE ViewPatterns #-}
6module Stack.Config where
10import Data.ByteString as BS
15import Stack.Config.Yaml as Yaml
18newtype StackResolver = StackResolver { fromStackResolver :: Text }
19 deriving (Eq, Ord, Show)
21makePrisms ''StackResolver
23unStackResolver :: StackResolver -> String
24unStackResolver = T.unpack . fromStackResolver
29 } deriving (Eq, Ord, Show)
35 | StackFilePath FilePath
37 | StackRepoGit RepoGit
38 deriving (Eq, Ord, Show)
40makePrisms ''PackageLocation
42data StackPackage = StackPackage
43 { _spLocation :: !PackageLocation
44 , _spExtraDep :: !Bool
45 } deriving (Eq, Ord, Show)
47makeLenses ''StackPackage
49data StackConfig = StackConfig
50 { _scResolver :: !StackResolver
51 , _scPackages :: ![StackPackage]
52 } deriving (Eq, Ord, Show)
54makeLenses ''StackConfig
56fromYamlConfig :: Yaml.Config -> StackConfig
57fromYamlConfig c = StackConfig{..}
59 _scResolver = coerce $ c ^. cResolver
61 (fromYamlPackage <$> c ^. cPackages . to (fromMaybe mempty)) ++
62 (fromYamlExtraDep <$> c ^. cExtraDeps . to (fromMaybe mempty))
64fromYamlPackage :: Yaml.Package -> StackPackage
65fromYamlPackage = \case
67 StackPackage (parseSimplePath p) False
68 Yaml.LocationSimple (Yaml.Location p extraDep) ->
69 StackPackage (parseSimplePath p) (fromMaybe False extraDep)
70 Yaml.LocationGit (Location git extraDep) ->
71 StackPackage (StackRepoGit $ fromYamlGit git) (fromMaybe False extraDep)
73 parseSimplePath (T.unpack -> p) = maybe (StackFilePath p) StackUri $ parseURI p
75fromYamlExtraDep :: Text -> StackPackage
76fromYamlExtraDep = flip StackPackage True . HackagePackage
78fromYamlGit :: Yaml.Git -> RepoGit
79fromYamlGit yg = RepoGit{..}
82 _rgCommit = yg ^. gCommit
84readStackConfig :: FilePath -> IO (Either String StackConfig)
85readStackConfig stackYaml =
86 second fromYamlConfig . decodeEither <$> BS.readFile stackYaml
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list