-
Notifications
You must be signed in to change notification settings - Fork 21
/
GlobalFlags.hs
51 lines (43 loc) · 1.95 KB
/
GlobalFlags.hs
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
module HackPort.GlobalFlags
( GlobalFlags(..)
, defaultGlobalFlags
, withHackPortContext
) where
import qualified Distribution.Verbosity as DV
import qualified Distribution.Simple.Setup as DSS
import qualified Distribution.Client.Config as DCC
import qualified Distribution.Client.GlobalFlags as DCG
import qualified Distribution.Client.Types as DCT
import qualified Distribution.Utils.NubList as DUN
import qualified Network.URI as NU
import System.FilePath ((</>))
import qualified Overlays
-- | Type containing global flags.
data GlobalFlags =
GlobalFlags { globalVersion :: DSS.Flag Bool
, globalNumericVersion :: DSS.Flag Bool
, globalPathToOverlay :: DSS.Flag (Maybe FilePath)
, globalPathToPortage :: DSS.Flag (Maybe FilePath)
}
-- | Default 'GlobalFlags'.
defaultGlobalFlags :: GlobalFlags
defaultGlobalFlags =
GlobalFlags { globalVersion = DSS.Flag False
, globalNumericVersion = DSS.Flag False
, globalPathToOverlay = DSS.Flag Nothing
, globalPathToPortage = DSS.Flag Nothing
}
-- | Default remote repository. Defaults to [hackage](hackage.haskell.org).
defaultRemoteRepo :: DCT.RemoteRepo
defaultRemoteRepo = DCC.addInfoForKnownRepos $ (DCT.emptyRemoteRepo (DCT.RepoName name)) { DCT.remoteRepoURI = uri }
where
Just uri = NU.parseURI "https://hackage.haskell.org/"
name = "hackage.haskell.org"
withHackPortContext :: DV.Verbosity -> GlobalFlags -> (DCG.RepoContext -> IO a) -> IO a
withHackPortContext verbosity global_flags callback = do
overlayPath <- Overlays.getOverlayPath verbosity (DSS.fromFlag $ globalPathToOverlay global_flags)
let flags = DCG.defaultGlobalFlags {
DCG.globalRemoteRepos = DUN.toNubList [defaultRemoteRepo]
, DCG.globalCacheDir = DSS.Flag $ overlayPath </> ".hackport"
}
DCG.withRepoContext verbosity flags callback