generic-env-0.1.1.0: Generic Environment Generator

Safe HaskellSafe
LanguageHaskell2010

GenericEnv

Synopsis

Documentation

fromEnv :: forall env. (Generic env, Envable (Rep env)) => EnvOptions -> IO (Either String env) Source #

Tries to produce type env from the environment variables. The Envable restriction is for ensuring type is a record-syntaxed product type.

data EnvOptions Source #

Constructors

EnvOptions 

Fields

  • modifyFieldNames :: String -> String

    Field names of the type can be modified. For a type:

      data MyEnv { _eName :: String, _eCount :: Int }
    

    you may want to eliminate the prefixes beforehand. Then options would be:

      defaultOptions { modifyFieldNames = drop 2 }
    
  • envKeyPrefix :: String

    Prefix for the environment variable keys. If your type is

      data MyEnv { name :: String, count :: Int }
    

    you might be using environment variables like the following:

      APP_NAME=genericenv
      APP_COUNT=3
    

    The prefix should be APP_ in this case.

withPrefix :: String -> EnvOptions Source #

This function is for generating the most common use case. Only sets the prefix over the default env options.