| Copyright | (c) Dennis Gosnell, 2016 |
|---|---|
| License | BSD-style (see LICENSE file) |
| Maintainer | cdep.illabout@gmail.com |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | Safe |
| Language | Haskell2010 |
System.ReadEnvVar
Description
This Haskell module exports functions for safely reading environment variables.
- readEnvVar :: Read a => String -> IO (Maybe a)
- readEnvVarDef :: Read a => String -> a -> IO a
Documentation
Lookup a value from an environment variable and read it in with
readMaybe.
>>>import System.Environment (setEnv)>>>setEnv "TEST_ENV_VAR" "2000">>>readEnvVar "TEST_ENV_VAR" :: IO (Maybe Int)Just 2000>>>readEnvVar "THIS_ENV_VAR_WILL_NOT_EXIST" :: IO (Maybe Int)Nothing
Arguments
| :: Read a | |
| => String | environment variable to lookup |
| -> a | default value to use if the environment variable
either does not exist, or cannot be |
| -> IO a |
Lookup a value from an environment variable and read it in with
readMaybe. If the environment variable doesn't exist, or it can't be
read, use the default value.
>>>import System.Environment (setEnv)>>>setEnv "TEST_ENV_VAR" "1000">>>readEnvVarDef "TEST_ENV_VAR" 5 :: IO Int1000>>>readEnvVarDef "THIS_ENV_VAR_WILL_NOT_EXIST" 5 :: IO Int5