generic-env: Generic Environment Generator

[ development, library, mit ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/yigitozkavci/generic-env#readme


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.1.1.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), containers, text [details]
License MIT
Copyright 2019 Yigit Ozkavci
Author Yigit Ozkavci
Maintainer yigitozkavci8@gmail.com
Category Development
Home page https://github.com/yigitozkavci/generic-env#readme
Bug tracker https://github.com/yigitozkavci/generic-env/issues
Source repo head: git clone https://github.com/yigitozkavci/generic-env
Uploaded by yigitozkavci at Tue Apr 30 20:01:47 UTC 2019
Distributions NixOS:0.1.1.0
Downloads 125 total (14 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-04-30 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for generic-env-0.1.0.0

[back to package description]

generic-env

generic-env lets you produce your generic type from a given subset of environment variables.

Usage

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}

module Example1 where

import GenericEnv
import GHC.Generics
import System.Environment

data AppEnv = AppEnv { name :: String, ver :: String } deriving (Generic, Show)

main :: IO ()
main = do
  setEnv "APP_NAME" "wow"
  setEnv "APP_VER" "1.0"
  print =<< fromEnv @AppEnv (withPrefix "APP_")
> main
Right (AppEnv {name = "wow", ver = "1.0"})

Let's change our version from String to Float:

data AppEnv = AppEnv { name :: String, ver :: Float } deriving (Generic, Show)

and run the same code:

> main
Right (AppEnv {name = "wow", ver = 1.0})

Next, try making the version an integer:

data AppEnv = AppEnv { name :: String, ver :: Int } deriving (Generic, Show)
> main
Left "Could not parse value of type 'Int' for the field named 'ver' from environment variable 'APP_VER=1.0'"

LICENSE

MIT License