A Scala wrapper for Typesafe config
libraryDependencies += "com.github.kxbmap" %% "configs" % "0.2.3"
import com.github.kxbmap.configs._
import com.typesafe.config.ConfigFactory
val config = ConfigFactory.load()
val a = config.get[Int]("a") // == config.getInt("a")
val b = config.get[String]("b") // == config.getString("b")
vsl c = config.get[List[Double]]("c") // Returns scala.List[Double], NOT java.util.List[java.lang.Double]
Use com.github.kxbmap.configs.Bytes
val Bytes(bytes) = config.get[Bytes]("bs") // bytes == config.getBytes("bs").longValue()
val m = config.get[Map[String, Int]]("m")
import scala.concurrent.duration.Duration
val d = config.get[Duration]("d")
val s = config.get[Option[String]]("string") // == Some("something")
val t = config.opt[String]("string") // alias
By default, get[Option[T]]
handles only ConfigException.Missing
// read missing value
val m = config.opt[String]("missing") // == None
// read wrong type value
val n = config.opt[Int]("string") // Exception! throws ConfigException.WrongType
Import implicit CatchCond
(alias for Throwable => Boolean
) value, change this behavior
import CatchCond.configException
// read wrong type value
val n = config.opt[Int]("string") // == None
val r = config.get[Eihter[Throwable, String]]("string") // == Right("something")
val l = config.get[Either[Throwable, Int]]("string") // == Left(ConfigException.WrongType(...))
val s = config.get[Try[String]]("string") // == Success("something")
val f = config.get[Try[Int]]("string") // == Failure(ConfigException.WrongType(...))
Apache License, Version 2.0