-
Notifications
You must be signed in to change notification settings - Fork 26
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
use config-annotation for easier reading of config files #62
Comments
config-annotation should be used as follows: Let's say i want to create a config file.
Instead of creating the kafka.config file, I have to create a trait like so :
and then whenever I want to use the config parameters, my class has to extend the trait like so
There is a side effect. There will be a file called kafka.conf generated in src/main/resources |
I believe I have a good hang of it now. Could you tell me where this will be useful in abandon. Where are the config files? I did a grep for config, but it gave too many results. |
In abandon, the config files are specified at run time through the command line flags. I thought the macro library would be useful while reading the config files. The current code has to explicitly read every field. It would be cool if we could just say:
where This is what I believed |
I like the idea of But I understood it as Could you please take a quick look and run this https://github.com/wacai/config-annotation-example |
Hi @hrj I was held up with other stuff for two weeks- sorry. I am back now :-) import net.ceedubs.ficus.Ficus._
import com.typesafe.config.{Config, ConfigFactory}
case class Account(name: String, alias: String)
class ConfigParser{
val config = ConfigFactory.parseString(
"""
services {
account {
name = "Assets:Current:Cash"
alias = "cash"
}
report {
title = "All"
type = balance
showZeroAmountAccounts = true
}
}
""".stripMargin)
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
val someAccount:Account = config.as[Account]("services.account")
}
object ConfigParser {
def main(args: Array[String]) {
val cf = new ConfigParser()
println(cf.someAccount.name + "\n" + cf.someAccount.alias)
}
} This is doing exactly what you suggested above. The line we are interested in is:
However, there is one major issue: |
@chidu8 Looks like good progress. About the exception, can you try using an case class Account(name: String, alias: Option[String]) or with a default value: case class Account(name:String, alias: String = "") or a combination of the two approaches (especially for the case class Account(name:String, alias: Option[String] = None)
|
config-annotation provides macros for easier reading of config files.
The text was updated successfully, but these errors were encountered: