Package Info


Parse environment variables


Here's a simple example of a program that uses 'envparse''s parser:

' module Main (main) where

import Control.Monad (unless) import Env

data Hello = Hello { name :: String, quiet :: Bool }

hello :: IO Hello hello = Env.parse (header "envparse example") $ &#x20; Hello <$> var (str <=< nonempty) "NAME" (help "Target for the greeting") &#x20; <*> switch "QUIET" (help "Whether to actually print the greeting") &#x20; main :: IO () main = do &#x20; Hello &#x7b;name, quiet&#x7d; <- hello &#x20; unless quiet $ &#x20; putStrLn ("Hello, " ++ name ++ "!") '

The 'NAME' environment variable is mandatory and contains the name of the person to greet. 'QUIET', on the other hand, is an optional boolean flag, false by default, that decides whether the greeting should be silent.

If the 'NAME' variable is undefined in the environment then running the program will result in the following help text:

' envparse example &#x20; Available environment variables: &#x20; &#x20; NAME Target for the greeting &#x20; QUIET Whether to actually print the &#x20; greeting &#x20; Parsing errors: &#x20; &#x20; NAME is unset '.

License: BSD-3-Clause



Package Version Update ID Released Package Hub Version Platforms Subpackages
0.4-bp150.2.4 info GA Release 2018-08-01 15
  • AArch64
  • ghc-envparse
  • ghc-envparse-devel
0.4-bp150.2.6 info GA Release 2018-07-30 15
  • ppc64le
  • x86-64
  • ghc-envparse
  • ghc-envparse-devel