Safe Haskell | None |
---|
Data.Yaml.Config.Internal
Contents
- data Config = Config [Key] Object
- newtype KeyError = KeyError Key
- type Key = Text
- load :: FilePath -> IO Config
- keys :: Config -> [Key]
- subconfig :: Failure KeyError m => Key -> Config -> m Config
- lookup :: (Failure KeyError m, FromJSON a) => Key -> Config -> m a
- lookupDefault :: FromJSON a => Key -> a -> Config -> a
- fullpath :: Config -> Key -> Key
Documentation
Type contains config section and path from root.
This error can be raised if config has not target path.
Work with files
load :: FilePath -> IO ConfigSource
Find file in filesystem and try to load it as YAML config.
May fail with InvalidYaml
if file not found.
>>>
config <- load "example.yaml"
Explore config
Show all first level config field's.
>>>
keys config
["section1","section2"]
Arguments
:: Failure KeyError m | |
=> Key | Subconfig name |
-> Config | (Sub)Config for find |
-> m Config | Founded Subconfig |
Get subconfig by name.
May fail with KeyError
if target key doesn't exist at current level.
>>>
:set -XOverloadedStrings
>>>
sub <- subconfig "section1" config
Arguments
:: (Failure KeyError m, FromJSON a) | |
=> Key | Field name |
-> Config | Config for find |
-> m a | Field value |
Get value for given key.
May fail with KeyError
if key doesn't exist.
>>>
keys sub
["field1","field2"]>>>
putStrLn =<< lookup "field1" sub
value1