Skip to content

Instantly share code, notes, and snippets.

@nod
Last active November 7, 2017 17:23
Show Gist options
  • Save nod/29a391f0eb4955d1ba3d34d12633fbbf to your computer and use it in GitHub Desktop.
Save nod/29a391f0eb4955d1ba3d34d12633fbbf to your computer and use it in GitHub Desktop.
For scala, using typesafe config, read default config and read runtime config if given via cmdline option
/*
Prior to this, I would build up `cfgMap` from my command line options.
If `'config` exists, that will load the run time config file and overlay it on top of the default config.
*/
// setup our default config
lazy val defaultConfig = ConfigFactory.parseResources("default.conf")
var conf = defaultConfig
// do we have a runtime config file?
val cfgFilePath = cfgMap.getOrElse('config, Nil)
if (cfgFilePath != Nil) {
lazy val userConfig = ConfigFactory
.parseFile(new File(cfgFilePath.toString))
conf = userConfig.withFallback(defaultConfig)
}
conf = conf.resolve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment