forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockFileBehavior.hs
More file actions
41 lines (37 loc) · 1.28 KB
/
LockFileBehavior.hs
File metadata and controls
41 lines (37 loc) · 1.28 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
{-# LANGUAGE NoImplicitPrelude #-}
module Stack.Types.LockFileBehavior
( LockFileBehavior (..)
, readLockFileBehavior
) where
import qualified Data.Map as Map
import Options.Applicative ( ReadM )
import qualified Options.Applicative.Types as OA
import qualified RIO.List as List
import Stack.Prelude
-- | How to interact with lock files
data LockFileBehavior
= LFBReadWrite
-- ^ Read and write lock files
| LFBReadOnly
-- ^ Read lock files, but do not write them
| LFBIgnore
-- ^ Entirely ignore lock files
| LFBErrorOnWrite
-- ^ Error out on trying to write a lock file. This can be used to
-- ensure that lock files in a repository already ensure
-- reproducible builds.
deriving (Bounded, Enum, Show)
-- | Parser for 'LockFileBehavior'
readLockFileBehavior :: ReadM LockFileBehavior
readLockFileBehavior = do
s <- OA.readerAsk
case Map.lookup s m of
Just x -> pure x
Nothing -> OA.readerError $ "Invalid lock file behavior, valid options: " ++
List.intercalate ", " (Map.keys m)
where
m = Map.fromList $ map (\x -> (render x, x)) [minBound..maxBound]
render LFBReadWrite = "read-write"
render LFBReadOnly = "read-only"
render LFBIgnore = "ignore"
render LFBErrorOnWrite = "error-on-write"