2020-07-14 22:00:58 +03:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
|
|
|
|
module Data.Environment
|
|
|
|
( Environment()
|
|
|
|
, getEnvironment
|
|
|
|
, mkEnvironment
|
|
|
|
, emptyEnvironment
|
|
|
|
, maybeEnvironment
|
2020-12-28 15:56:00 +03:00
|
|
|
, lookupEnv
|
|
|
|
, Data.Environment.toList
|
|
|
|
) where
|
2020-07-14 22:00:58 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
import Data.Aeson
|
|
|
|
import Hasura.Prelude
|
2020-07-14 22:00:58 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
import qualified Data.Map as M
|
2020-07-14 22:00:58 +03:00
|
|
|
import qualified System.Environment
|
|
|
|
|
|
|
|
newtype Environment = Environment (M.Map String String) deriving (Eq, Show, Generic)
|
|
|
|
|
|
|
|
instance FromJSON Environment
|
|
|
|
|
|
|
|
getEnvironment :: IO Environment
|
|
|
|
getEnvironment = mkEnvironment <$> System.Environment.getEnvironment
|
|
|
|
|
|
|
|
maybeEnvironment :: Maybe Environment -> Environment
|
|
|
|
maybeEnvironment = fromMaybe emptyEnvironment
|
|
|
|
|
|
|
|
mkEnvironment :: [(String, String)] -> Environment
|
|
|
|
mkEnvironment = Environment . M.fromList
|
|
|
|
|
|
|
|
emptyEnvironment :: Environment
|
|
|
|
emptyEnvironment = Environment M.empty
|
|
|
|
|
|
|
|
lookupEnv :: Environment -> String -> Maybe String
|
|
|
|
lookupEnv (Environment es) k = M.lookup k es
|
2020-12-28 15:56:00 +03:00
|
|
|
|
|
|
|
toList :: Environment -> [(String, String)]
|
|
|
|
toList (Environment e) = M.toList e
|