richenv-0.1.0.1: Rich environment variable setup for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

RichEnv.Setters

Description

This module contains functions for setting environment variables from the RichEnv types as well as functions for transforming between the different types used by this library (Values, Mappings and Prefixes).

Synopsis

Documentation

mappingsToValues :: Environment -> Mappings -> Values Source #

Takes an environment variable list and all the name mappings and prepares a set of environment variables according to the RichEnv rules.

>>> mappingsToValues [("FOO", "bar"), ("SOME", "thing")] (Mappings $ HM.fromList [("OTHER", "FOO")])
Values {unValues = fromList [("OTHER","bar")]}

prefixesToValues :: Environment -> Prefixes -> Values Source #

Takes an environment variable list and all the prefix mappings and prepares a set of environment variables according to the RichEnv rules.

>>> prefixesToValues [("FOO", "bar"), ("SOME", "thing")] (Prefixes $ HM.fromList [("OTHER", ["FOO"])])
Values {unValues = fromList [("OTHER","bar")]}

valuesToEnv :: Values -> IO () Source #

Takes a Values object and sets its contents as environment variables.

valuesToEnvList :: Values -> Environment Source #

Takes a Values object and transforms it into a list of key-value pairs representing environment variables.

valuesToEnvList = Data.HashMap.Strict.toList . unValues

richEnvToValues :: RichEnv -> Environment -> Values Source #

Takes an environment variable list and a RichEnv object and generates a Values object.

>>> richEnvToValues RichEnv.Types.defaultRichEnv [("FOO", "bar"), ("SOME", "thing")]
Values {unValues = fromList []}
>>> import RichEnv.Types.Values as V
>>> let richEnvValue = RichEnv.Types.defaultRichEnv { values = V.fromList [("OTHER", "var")]}
>>> let envList = [("FOO", "bar"), ("SOME", "thing")]
>>> richEnvToValues richEnvValue envList
Values {unValues = fromList [("OTHER","var")]}
>>> import RichEnv.Types.Mappings as M
>>> let richEnvValue = RichEnv.Types.defaultRichEnv { mappings = M.fromList [("SOME", "FOO")]}
>>> let envList = [("FOO", "bar"), ("SOME", "thing"), ("SOME", "other")]
>>> richEnvToValues richEnvValue envList
Values {unValues = fromList [("SOME","bar")]}
>>> import RichEnv.Types.Prefixes as P
>>> let richEnvValue = RichEnv.Types.defaultRichEnv { prefixes = P.fromList [("NEW_", ["PREFIXED_"])]}
>>> let envList = [("PREFIXED_VAR", "content"), ("PREFIXED_VAR2", "content2")]
>>> richEnvToValues richEnvValue envList
Values {unValues = fromList [("NEW_VAR","content"),("NEW_VAR2","content2")]}