how to parse generic case class fields using scala option parser?

Viewed 1176

I have a case class includes around 20 fields , all of which are primitive types.

case class A( f1: String, f2: Int .....)

and I have to parse these fields all from command line (unfortunately). I can , but I really don't want to write this 20 times

opt[String]("f1") required() valueName "<f1>" action { (x, c) =>
    c.copy(f1 = x)
  } text "f1 is required"
//...repeat 20 times

I can obtain the field name and filed type through reflection, but I have no idea how to stuck those information to this call within a for loop

I can connect this with shapeless but I'm still not familiar with that and can this be done without shapeless ?

==

scala option parser => scopt

2 Answers
Related