HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Package0.6.0System

envparse

Parse environment variables

Modules

7 modules
  • Env41Here's a simple example of a program that uses envparse's parser: module Main (main) where
  • Env.Generic4Using the Generic facility, this module can derive Parsers automatically. If you have a simple record: {-# LANGUAGE DeriveGeneric #-}
Internal modules · 5

Description

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") $ Hello <$> var (str <=< nonempty) "NAME" (help "Target for the greeting") <*> switch "QUIET" (help "Whether to actually print the greeting") main :: IO () main = do Hello {name, quiet} <- hello unless quiet $ 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 Available environment variables: NAME Target for the greeting QUIET Whether to actually print the greeting Parsing errors: NAME is unset

Depends on

2 packages

Used by in this set · 0

Nothing in this set depends on it.