MainApi

confuse.api.MainApi
trait MainApi extends PlatformApi

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Api
object default.type

Members list

Concise view

Value members

Concrete methods

def defaultEnvKeyReplacer: String => String

A function to transform the name of an environment variable into a configuration path.

A function to transform the name of an environment variable into a configuration path.

This can be overridden to globally change the behavior instead of overriding it in every call of read.

Attributes

def defaultReaders: Map[String, FileReader]

Configuration readers for file extensions.

Configuration readers for file extensions.

This can be overridden to globally change the behavior instead of overriding it in every call of read.

Attributes

def read(paths: Iterable[FilePath], pwd: Path, readers: Map[String, FileReader], env: Map[String, String], envPrefix: String, envKeyReplacer: String => String, envBinds: Iterable[(String, String)], props: Map[String, String], propsPrefix: String, propsBinds: Iterable[(String, String)], args: Iterable[(String, String)], dest: Config): Config

Read a configuration from various sources and formats.

Read a configuration from various sources and formats.

The configuration will be the result of merging configuration objects in the order of the parameters of this method. I.e.

  • start by reading files and directories
  • add configurations from environment variables
  • add configurations from system properties
  • add configuration from command line arguments

Merging of configuration objects means that object's keys are merged recursively. Other types however are replaced. Example:

Original

{
 "a": "lhs"
 "b": {
    "inner": {
       "foo": "lhs"
     }
  }
}

merge with

{
 "b": {
    "inner": {
       "foo": "rhs"
     }
  }
 "c": "rhs"
}

results in

{
 "a": "lhs"
 "b": {
    "inner": {
       "foo": "rhs"
     }
  }
 "c": "rhs"
}

Attributes

args

Command line arguments that should be interpreted as configurations.

dest

Root configuration object into which all other configuration will be merged. This can be set to build configurations through multiple calls to read. Defaults to an empty configuration.

env

Environment variables available for reading. Note that by default none will be read, unless other env* parameters are specified. Defaults to system environment variables.

envBinds

An association of environment variables to configuration paths. This is used to manually bind environment variables, for example if the prefix approach cannot be used. For example if the env contains SOME_SETTING=1 and the bindings contain "SOME_SETTING" -> "foo.bar", then this will result in the configuration foo.bar=1

envKeyReplacer

A function to transform the name of an environment variable into a configuration path. This overrides the default defaultEnvKeyReplacer if set.

envPrefix

Automatically read environment variables starting with this prefix, if set. Any environment variables read in such a way will have the prefix stripped before being transformed into a configuration path via the envKeyReplacer. For example if the env contains APP_FOO_BAR=1 and the prefix is given as APP_, then this will result in the configuration foo.bar=1.

paths

Paths of configuration files or directories containing config files. In case a path is a directory, it will be traversed for config files sorted in lexicographical order (only one level deep). In case a path is a file, it will be parsed based on extension. See the readers param.

props

System properties available for reading. Note that by default none will be read, unless other props* parameters are specified. Defaults to the current runtime's properties (on the JVM).

propsBinds

An association of properties to configuration paths. This is used to manually bind properties, for example if the prefix approach cannot be used. For example if the properties contain some.property=1 and the bindings contain "some.property" -> "foo.bar", then this will result in the configuration foo.bar=1

propsPrefix

Automatically read system properties starting with this prefix, if set. Any properties read in such a way will have the prefix stripped before being read as a configuration path. For example if the properties contain app.foo.bar=1 and the prefix is given as app., then this will result in the configuration foo.bar=1.

pwd

Root directory to use if files are given as relative paths. Defaults to current working directory.

readers

Additional readers for file extensions. See defaultReaders in the API trait.