| Copyright | (C) 2014 Yorick Laupa |
|---|---|
| License | (see the file LICENSE) |
| Maintainer | Yorick Laupa <yo.eight@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Data.Config
Description
Config is a small and typesafe configuration library. It provides good error messages and comes with a bottom-up typechecker in order to catch more configuration errors.
Here some use-cases:
>>>foo = ["bar", { baz : 42 }]foo:1:8-13: Expecting String but having Object
Reason: List has only one inner type
>>>foo = ["bar"] [{ baz : 42 }]foo:1:7-14: Expecting List[String] but having List[Object]
Reason: You can't merge Lists of different types
It uses Typesafe-config format: HOCON. HOCON stands for Human-Optimized Config Object Notation. It's basically a JSON superset
Here's an example:
-- app.conf
# This is a comment
foo.bar = ${toto}
toto = false
rawString = """
This is a multi-
lines String
"""
another.string = "I'm a String"
one.more.string = one more string
nested {
list: [ one
, 1
, "both"]
homing = {
pass: { b: feez } { a: "Prop"}
}
another: [1,2,3] [4,5,6]
}How to use:
-- Example.hs
{--}
import Data.Config
import Data.Text (Text)
data Foo = Foo { fooPort :: Int, fooAddr :: Text }
main :: IO ()
main = do
foo <- loadFooProps
withFoo foo
where
loadFooProps = do
config <- loadConfig "conf/baz.conf"
port <- getInteger "foo.port" config
addr <- getString "foo.addr" config
return (Foo port addr)
withFoo :: Foo -> IO ()
withFoo = ...
- data Config
- loadConfig :: (MonadIO m, MonadThrow m) => FilePath -> m Config
- getInteger :: MonadThrow m => Text -> Config -> m Integer
- getParsec :: MonadThrow m => (forall s. Parsec Text s a) -> Text -> Config -> m a
- getString :: MonadThrow m => Text -> Config -> m Text
- getBool :: MonadThrow m => Text -> Config -> m Bool
- getStrings :: MonadThrow m => Text -> Config -> m [Text]
- getBools :: MonadThrow m => Text -> Config -> m [Bool]
- getIntegers :: MonadThrow m => Text -> Config -> m [Integer]
- getParsecs :: MonadThrow m => (forall s. Parsec Text s a) -> Text -> Config -> m [a]
Documentation
loadConfig :: (MonadIO m, MonadThrow m) => FilePath -> m Config Source #
getInteger :: MonadThrow m => Text -> Config -> m Integer Source #
getStrings :: MonadThrow m => Text -> Config -> m [Text] Source #
getIntegers :: MonadThrow m => Text -> Config -> m [Integer] Source #
getParsecs :: MonadThrow m => (forall s. Parsec Text s a) -> Text -> Config -> m [a] Source #