Safe Haskell | None |
---|---|
Language | Haskell2010 |
- 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 Config Source
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
keys :: Config -> [Key] Source
Show all first level config field's.
>>>
keys config
["section1","section2"]
Get subconfig by name.
May fail with KeyError
if target key doesn't exist at current level.
>>>
:set -XOverloadedStrings
>>>
sub <- subconfig "section1" config
Get value for given key.
May fail with KeyError
if key doesn't exist.
>>>
keys sub
["field1","field2"]>>>
putStrLn =<< lookup "field1" sub
value1
Find value in config and return it or return default value.
>>>
lookupDefault "field3" "def" sub
"def"