generic-env: Generic Environment Generator

[ development, library, mit ] [ Propose Tags ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 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 2019-04-30T20:24:16Z
Distributions NixOS:0.1.1.0
Downloads 984 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-04-30 [all 1 reports]

Readme for generic-env-0.1.1.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