Copyright | (c) David Johnson 2015 |
---|---|
Maintainer | djohnson.m@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
{-# LANGUAGE DeriveGeneric #-} module Main ( main ) where import System.Envy import GHC.Generics data PGConfig = PGConfig { pgHost :: String -- "PG_HOST" , pgPort :: Int -- "PG_PORT" } deriving (Generic, Show) -- Default instance used if environment variable doesn't exist instance DefConfig PGConfig where defConfig = PGConfig "localhost" 5432 instance FromEnv PGConfig -- Generically produces the following body (no implementation needed if using Generics): -- fromEnv = PGConfig <$> envMaybe "PG_HOST" .!= "localhost" -- <*> envMaybe "PG_PORT" .!= 5432 main :: IO () main = print =<< do decodeEnv :: IO (Either String PGConfig) -- PGConfig { pgHost = "custom-pg-url", pgPort = 5432 }
Synopsis
- class FromEnv a where
- class ToEnv a where
- class Typeable a => Var a where
- data EnvList a = EnvList [EnvVar]
- data EnvVar = EnvVar {}
- newtype Parser a = Parser {}
- decodeEnv :: FromEnv a => IO (Either String a)
- decodeWithDefaults :: FromEnv a => a -> IO a
- decode :: FromEnv a => IO (Maybe a)
- showEnv :: IO ()
- setEnvironment :: EnvList a -> IO (Either String ())
- setEnvironment' :: ToEnv a => a -> IO (Either String ())
- unsetEnvironment :: EnvList a -> IO (Either String ())
- unsetEnvironment' :: ToEnv a => a -> IO (Either String ())
- makeEnv :: [EnvVar] -> EnvList a
- env :: Var a => String -> Parser a
- envMaybe :: Var a => String -> Parser (Maybe a)
- (.=) :: Var a => String -> a -> EnvVar
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- class DefConfig a where
- defConfig :: a
- data Option = Option {}
- defOption :: Option
- runEnv :: Parser a -> IO (Either String a)
- gFromEnvCustom :: forall a. (Generic a, GFromEnv (Rep a)) => Option -> Maybe a -> Parser a
Classes
Type class for objects which can be converted to a set of environment variable settings.
class Typeable a => Var a where Source #
Class for converting to / from an environment variable
Convert a value into an environment variable.
fromVar :: String -> Maybe a Source #
Parse an environment variable.
Instances
Var Bool Source # | |
Var Double Source # | |
Var Int Source # | |
Var Int8 Source # | |
Var Int16 Source # | |
Var Int32 Source # | |
Var Int64 Source # | |
Var Integer Source # | |
Var Word8 Source # | |
Var Word16 Source # | |
Var Word32 Source # | |
Var Word64 Source # | |
Var () Source # | |
Var String Source # | |
Var ByteString Source # | |
Defined in System.Envy | |
Var ByteString Source # | |
Defined in System.Envy | |
Var Text Source # | |
Var Text Source # | |
Var UTCTime Source # | |
Var Day Source # | |
Var a => Var (Maybe a) Source # | |
List of environment variables. Captures a "phantom type" which allows the type checker to detect the proper implementation of toEnv to use.
Variable type, smart constructor for handling environment variables.
EnvVar | |
|
Parser Monad for environment variable retrieval
Instances
Monad Parser Source # | |
Functor Parser Source # | |
Applicative Parser Source # | |
MonadIO Parser Source # | |
Defined in System.Envy | |
Alternative Parser Source # | |
MonadPlus Parser Source # | |
MonadError String Parser Source # | |
Defined in System.Envy throwError :: String -> Parser a # catchError :: Parser a -> (String -> Parser a) -> Parser a # |
Functions
decodeWithDefaults :: FromEnv a => a -> IO a Source #
Environment retrieval with default values provided
setEnvironment :: EnvList a -> IO (Either String ()) Source #
Set environment via a ToEnv constrained type
setEnvironment' :: ToEnv a => a -> IO (Either String ()) Source #
Set environment directly using a value of class ToEnv
unsetEnvironment :: EnvList a -> IO (Either String ()) Source #
Unset Environment from a ToEnv
constrained type
unsetEnvironment' :: ToEnv a => a -> IO (Either String ()) Source #
Unset Environment using a value of class ToEnv
Environment variable getter. Fails if the variable is not set or fails to parse.
Environment variable getter returning Maybe
:: Var a | |
=> String | The variable name to set. |
-> a | Object to set in the environment. |
-> EnvVar | Mapping of Variable to Value. |
Infix environment variable setter
Smart constructor for producing types of EnvVar
:: Parser (Maybe a) | Parser that might fail. |
-> a | Value to return if the parser fails. |
-> Parser a | Parser that returns the default on failure. |
For use with envMaybe
for providing default arguments.
Generics
For customizing environment variable generation
Option | |
|