Base.hs 726 Bytes
Newer Older
1
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2
3
4

module Oracles.Base (
    ConfigKey (..),
Andrey Mokhov's avatar
Andrey Mokhov committed
5
    askConfigWithDefault, askConfig
6
7
    ) where

8
import Util
9
import Development.Shake
10
11
import Development.Shake.Classes

Andrey Mokhov's avatar
Andrey Mokhov committed
12
13
newtype ConfigKey = ConfigKey String
    deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
14
15
16

askConfigWithDefault :: String -> Action String -> Action String
askConfigWithDefault key defaultAction = do
17
    maybeValue <- askOracle $ ConfigKey key
18
19
20
21
22
23
    case maybeValue of
        Just value -> return value
        Nothing    -> defaultAction

askConfig :: String -> Action String
askConfig key = askConfigWithDefault key $
24
    redError $ "Cannot find key '" ++ key ++ "' in configuration files."