Base.hs 701 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
8
9
10
    ) where

import Base
import Development.Shake.Classes

Andrey Mokhov's avatar
Andrey Mokhov committed
11
12
newtype ConfigKey = ConfigKey String
    deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
13
14
15
16
17
18
19
20
21
22
23

askConfigWithDefault :: String -> Action String -> Action String
askConfigWithDefault key defaultAction = do
    maybeValue <- askOracle $ ConfigKey key 
    case maybeValue of
        Just value -> return value
        Nothing    -> defaultAction

askConfig :: String -> Action String
askConfig key = askConfigWithDefault key $
    error $ "\nCannot find key '" ++ key ++ "' in configuration files."