Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides functions to set environment variables or retrieve an environment variable list according to a RichEnv
object input, which defines:
- A list of environment variables to be set with their values.
- Mapping the name from one existing environment variable name to another (If there's an environment variable
FOO=bar
, a mapping("SOME", "FOO")
will generate an environment variable definitionSOME
with the contents of the variableFOO
). - Mapping the prefixes of existing environment variables to a new prefix (If there's an environment variable
FOO_VAR=bar
, a prefix mapping("SOME", ["FOO"])
will generate an environment variable definitionSOME_VAR
with the contents of the variableFOO_VAR
).
Synopsis
- data RichEnv = RichEnv {}
- type Environment = [(Text, Text)]
- toEnvList :: RichEnv -> Environment -> Environment
- toEnvMap :: RichEnv -> Environment -> HashMap Text Text
- setRichEnv :: RichEnv -> Environment -> IO ()
- setRichEnvFromCurrent :: RichEnv -> IO ()
- toEnvListFromCurrent :: RichEnv -> IO Environment
- toEnvMapFromCurrent :: RichEnv -> IO (HashMap Text Text)
- clearEnvironment :: [(String, String)] -> IO ()
Types
Type that represents a set of rules that generate environment variables. A value of this type can be retrieved from a configuration file (e.g. YAML) due to its FromJSON
instance, or persisted into one with ToJSON
.
Instances
FromJSON RichEnv Source # | |
Defined in RichEnv.Types | |
ToJSON RichEnv Source # | |
Monoid RichEnv Source # | |
Semigroup RichEnv Source # | |
Generic RichEnv Source # | |
Show RichEnv Source # | |
Eq RichEnv Source # | |
type Rep RichEnv Source # | |
Defined in RichEnv.Types type Rep RichEnv = D1 ('MetaData "RichEnv" "RichEnv.Types" "richenv-0.1.0.2-IjLZG29aO0FKDd3ReuTYyL" 'False) (C1 ('MetaCons "RichEnv" 'PrefixI 'True) (S1 ('MetaSel ('Just "values") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Values) :*: (S1 ('MetaSel ('Just "mappings") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Mappings) :*: S1 ('MetaSel ('Just "prefixes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Prefixes)))) |
type Environment = [(Text, Text)] Source #
A list of key-value pairs representing environment variables.
Environment transformations
toEnvList :: RichEnv -> Environment -> Environment Source #
Get a key-value list of environment variables processing the passed environment with the RichEnv
input.
toEnvList re env = valuesToEnvList (toEnvValues re env)
toEnvMap :: RichEnv -> Environment -> HashMap Text Text Source #
Get a hashmap of environment variables processing the passed environment with the RichEnv
input. The idea is that the output could be passed to functions like Yaml's applyEnvValue.
toEnvMap re env = unValues (toEnvValues re env)
Functions using IO
to get the environment from the current process
setRichEnv :: RichEnv -> Environment -> IO () Source #
Sets the environment variables available for the current process abiding to the RichEnv
rules.
setRichEnvFromCurrent :: RichEnv -> IO () Source #
Sets the environment variables available for the current process by checking the current environment variables and applying the RichEnv
rules.
setRichEnvFromCurrent re = getEnvironment >>= setRichEnv re . toEnvironment
toEnvListFromCurrent :: RichEnv -> IO Environment Source #
Get a key-value list of environment variables processing the current environment with the RichEnv
input.
toEnvListFromCurrent re = toEnvList re . toEnvironment <$> getEnvironment
toEnvMapFromCurrent :: RichEnv -> IO (HashMap Text Text) Source #
Get a hashmap of environment variables processing the current environment with the RichEnv
input. The idea is that the output could be passed to functions like Yaml's applyEnvValue.
toEnvMapFromCurrent re = toEnvMap re . toEnvironment <$> getEnvironment