envparse-0.4: Parse environment variables

Safe HaskellSafe
LanguageHaskell2010

Env.Internal.Parser

Synopsis

Documentation

newtype Parser e a #

An environment parser

Constructors

Parser 

Fields

Instances

Functor (Parser e) # 

Methods

fmap :: (a -> b) -> Parser e a -> Parser e b #

(<$) :: a -> Parser e b -> Parser e a #

Applicative (Parser e) # 

Methods

pure :: a -> Parser e a #

(<*>) :: Parser e (a -> b) -> Parser e a -> Parser e b #

(*>) :: Parser e a -> Parser e b -> Parser e b #

(<*) :: Parser e a -> Parser e b -> Parser e a #

Alternative (Parser e) # 

Methods

empty :: Parser e a #

(<|>) :: Parser e a -> Parser e a -> Parser e a #

some :: Parser e a -> Parser e [a] #

many :: Parser e a -> Parser e [a] #

data VarF e a #

Instances

Functor (VarF e) # 

Methods

fmap :: (a -> b) -> VarF e a -> VarF e b #

(<$) :: a -> VarF e b -> VarF e a #

parsePure :: Parser e a -> [(String, String)] -> Either [(String, e)] a #

Try to parse a pure environment

eachUnsetVar :: Applicative m => Parser e a -> (String -> m b) -> m () #

newtype Mod t a #

This represents a modification of the properties of a particular Parser. Combine them using the Monoid instance.

Constructors

Mod (t a -> t a) 

Instances

Monoid (Mod t a) # 

Methods

mempty :: Mod t a #

mappend :: Mod t a -> Mod t a -> Mod t a #

mconcat :: [Mod t a] -> Mod t a #

prefixed :: String -> Parser e a -> Parser e a #

The string to prepend to the name of every declared environment variable

var :: AsUnset e => Reader e a -> String -> Mod Var a -> Parser e a #

Parse a particular variable from the environment

>>> var str "EDITOR" (def "vim" <> helpDef show)

data Var a #

Environment variable metadata

Constructors

Var 

Fields

Instances

HasKeep Var # 

Methods

setKeep :: Var a -> Var a

HasHelp Var # 

Methods

setHelp :: String -> Var a -> Var a

type Reader e a = String -> Either e a #

An environment variable's value parser. Use (<=<) and (>=>) to combine these

str :: IsString s => Reader e s #

The trivial reader

nonempty :: (AsEmpty e, IsString s) => Reader e s #

The reader that accepts only non-empty strings

splitOn :: Char -> Reader e [String] #

The reader that splits a string into a list of strings consuming the separator.

auto :: (AsUnread e, Read a) => Reader e a #

The reader that uses the Read instance of the type

def :: a -> Mod Var a #

The default value of the variable

Note: specifying it means the parser won't ever fail.

helpDef :: (a -> String) -> Mod Var a #

Show the default value of the variable in help.

showDef :: Show a => Mod Var a #

Use the Show instance to show the default value of the variable in help.

flag #

Arguments

:: a

default value

-> a

active value

-> String 
-> Mod Flag a 
-> Parser e a 

A flag that takes the active value if the environment variable is set and non-empty and the default value otherwise

Note: this parser never fails.

switch :: String -> Mod Flag Bool -> Parser e Bool #

A simple boolean flag

Note: this parser never fails.

data Flag a #

Flag metadata

Instances

HasKeep Flag # 

Methods

setKeep :: Flag a -> Flag a

HasHelp Flag # 

Methods

setHelp :: String -> Flag a -> Flag a

class HasHelp t #

A class of things that can have a help message attached to them

Minimal complete definition

setHelp

Instances

HasHelp Flag # 

Methods

setHelp :: String -> Flag a -> Flag a

HasHelp Var # 

Methods

setHelp :: String -> Var a -> Var a

help :: HasHelp t => String -> Mod t a #

Attach help text to the variable

class HasKeep t #

A class of things that can be still kept in an environment when the parsing has been completed.

Minimal complete definition

setKeep

Instances

HasKeep Flag # 

Methods

setKeep :: Flag a -> Flag a

HasKeep Var # 

Methods

setKeep :: Var a -> Var a

keep :: HasKeep t => Mod t a #

Keep a variable.