Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplest way make config file selectable #908

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/main/scala/stryker4s/config/ConfigReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ object ConfigReader {

implicit val hint: ProductHint[Config] = ProductHint[Config](allowUnknownKeys = false)

def readConfig(confSource: ConfigSource = ConfigSource.file("stryker4s.conf"))(implicit log: Logger): Config = {
lazy val defaultConfig = ConfigSource.file(System.getProperty("stryker4s.config.file", "stryker4s.conf"))

def readConfig(confSource: ConfigSource = defaultConfig)(implicit log: Logger): Config = {
Reader
.withoutRecovery[Config](confSource)
.recoverWithReader(Failure.onUnknownKey)
Expand All @@ -25,7 +27,7 @@ object ConfigReader {
}

def readConfigOfType[T](
confSource: ConfigSource = ConfigSource.file("stryker4s.conf")
confSource: ConfigSource = defaultConfig
)(implicit log: Logger, pureconfig: PureConfigReader[T]): Either[ConfigReaderFailures, T] =
Reader.withoutRecovery[T](confSource).tryRead

Expand Down Expand Up @@ -75,7 +77,7 @@ object ConfigReader {
/** Attempt to read a config
*/
def tryRead: Reader.Result[T] = {
log.info(s"Attempting to read config from stryker4s.conf")
log.info(s"Attempting to read config from ${defaultConfig}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not toString nicely... Needs to separate file name from config object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the getProperty or default in a separate variable to properly log the file location?

configSource
.at("stryker4s")
.load[T]
Expand Down