Last active
November 7, 2017 17:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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