let path: String? = config["PATH"]
let port: Int? = config["HTTP_PORT"]
let key = Key("myKey")
let value = config[key]
let value = config[["key", "nested"]]
let value = config[["array", 2]]
extension Key {
static let clientId = Key("SECRET_CLIENT_ID")
}
let value = config[.clientId]
Require the value
For required values you can use require method which throws ConfigurationError.missing(key:) if value is not found.
Conf
Config made easy
This package provide easy way to work with configs. Mostly usefull in CLI-tools. Extentable and customisable.
Contents
Usage
For more details please refer the tests
Creating the config
Load configurations
Data representation
All values are stored as
Key
-String
pairs. There are convenience methods to useLosslessStringConvertible
.The
Key
represents the value position in the provided source.For basic key-value formats it is just a string.
For nested types key is the array of strings.
Arrays are mapped as multiple key-value pairs:
Reading the value
Values can be accessed via subscripts
Require the value
For required values you can use
require
method which throwsConfigurationError.missing(key:)
if value is not found.Updating values
Values can be updated via subscript
Creating the keys
Working with process environment
Conf
can fallback to the environment variables. This is controlled byuseEnvironment
variable in the constructor.Env values can be assessed separately with
Environment
Customisation
Adding data format
If you want to add support for different config format you just need to implement your own parser function and call
load
withFormat.custom
.For example here is how
yaml
support can be added with YamsCustom parsing
It is also possbile to provide completelly custom implementation of the data fetching behaviour. To do this you need to adopt
ConfigurationProvider
TODO