forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCabalConfigKey.hs
More file actions
37 lines (31 loc) · 1.23 KB
/
CabalConfigKey.hs
File metadata and controls
37 lines (31 loc) · 1.23 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Types.CabalConfigKey
( CabalConfigKey (..)
, parseCabalConfigKey
) where
import qualified Data.Text as T
import Pantry.Internal.AesonExtended
( FromJSON (..), FromJSONKey (..), FromJSONKeyFunction (..)
, withText
)
import Stack.Prelude
-- | Which packages do configure opts apply to?
data CabalConfigKey
= CCKTargets -- ^ See AGOTargets
| CCKLocals -- ^ See AGOLocals
| CCKEverything -- ^ See AGOEverything
| CCKPackage !PackageName -- ^ A specific package
deriving (Show, Read, Eq, Ord)
instance FromJSON CabalConfigKey where
parseJSON = withText "CabalConfigKey" parseCabalConfigKey
instance FromJSONKey CabalConfigKey where
fromJSONKey = FromJSONKeyTextParser parseCabalConfigKey
parseCabalConfigKey :: (Monad m, MonadFail m) => Text -> m CabalConfigKey
parseCabalConfigKey "$targets" = pure CCKTargets
parseCabalConfigKey "$locals" = pure CCKLocals
parseCabalConfigKey "$everything" = pure CCKEverything
parseCabalConfigKey name =
case parsePackageName $ T.unpack name of
Nothing -> fail $ "Invalid CabalConfigKey: " ++ show name
Just x -> pure $ CCKPackage x