解析字段(eg-master:String="") 有效,但如果这是在另一个案例类中,比如下面给出的案例类 Job(SparkArgs),我需要解析 JobArgs
case class SparkArgs(master: String)
val parser = new scopt.OptionParser[SparkArgs]("testing") {
head("spark-example", "2.11")
opt[String]('c', "master").required().valueName("spark-master").
action((x, c) => c.copy(master = x)).
text("Setting master is required")
}
parser.parse(args, SparkArgs()) match {
case Some(config) =>
// do stuff
println(config.master)
case None => // failed
}
//I am able to parse master above by >> run --master=local[2]
//Now how to parse if there are case class as parameters instead of String and Int and also those fields needs to be parsed,say scopt.OptionParser[JobArgs]
//eg -
case class JobArgs(sparkArgs: SparkArgs, kafkaArgs: KafkaArgs)
case class KafkaArgs(
kafkaPORT: String="",
checkpointPath: String="src/main/resources/checkpoints"
)
case class SparkArgs(master: String = "")
//I tried-
val parser = new scopt.OptionParser[JobArgs]("testing") {
head("spark-example", "2.11")
//Now how to parse all those fields which are master and kafkaPORT here
}
//and run similarly as>> run --master=local[2] --kafkaPORT=localhost:9092