yaml-config-0.4.0: Configuration management

Safe HaskellNone
LanguageHaskell2010

Data.Yaml.Config.Internal

Contents

Synopsis

Types

data Config Source

Type contains config section and path from root.

Constructors

Config [Key] Object 

newtype KeyError Source

This error can be raised if config has not target path.

Constructors

KeyError Key 

type Key = Text Source

Config or field name

Loading

load :: FilePath -> IO Config Source

Attempts to load a config from a given YAML file. Fails with InvalidYaml if the file does not exist.

>>> config <- load "example.yaml"

Access functions

keys :: Config -> [Key] Source

Returns all toplevel keys in a config.

>>> keys config
["section1","section2"]

subconfig Source

Arguments

:: Monad m 
=> Key

Subconfig name

-> Config

(Sub)Config to narrow into

-> m Config

Subconfig

Narrows into a config section corresponding to a given key. Fails with a KeyError if a key doesn't exist at the current level.

>>> :set -XOverloadedStrings
>>> sub <- subconfig "section1" config

lookup Source

Arguments

:: (Monad m, FromJSON a) 
=> Key

Field name

-> Config

Config to query

-> m a

Looked up value

Returns a value for a given key. Fails with a KeyError if the key doesn't exist.

>>> keys sub
["field1","field2"]
>>> putStrLn =<< lookup "field1" sub
value1

lookupDefault Source

Arguments

:: FromJSON a 
=> Key

Field name

-> a

Default value

-> Config

Config to query

-> a

Looked up or default value

Returns a value for a given key or a default value if a key doesn't exist.

>>> lookupDefault "field3" "def" sub
"def"

fullpath :: Config -> Key -> Key Source

Returns full path from the root to the given key. Levels are separated by dots.

>>> fullpath sub "field1"
"section1.field1"