Skip to content

Instantly share code, notes, and snippets.

@Rogach
Created April 8, 2012 11:34
Show Gist options
  • Save Rogach/2336746 to your computer and use it in GitHub Desktop.
Save Rogach/2336746 to your computer and use it in GitHub Desktop.
scallop examples 2
object Conf extends ScallopConf(List("-a","3","-b","5","tree")) {
val apples = opt[Int]("apples")
val bananas = opt[Int]("bananas")
verify
}
Conf.apples() // 3
Conf.bananas.get // Some(5)
object Conf extends ScallopConf(List("-a","3","-b","5","tree")) {
val applesO = opt[Int]("apples")
lazy val apples = apples.get.map(a => if (a > 3) "plenty" else "few").getOrElse("zero")
val bananas = opt[Int]("bananas")
val name = trailArg[String]()
verify
val bananasValue = bananas() + 3
}
Conf.apples // "few"
Conf.bananasValue // 8
object Conf {
var apples:Int = 0
var bananas:Int = 0
}
// ... parsing options ...
Conf.apples = parser.getOption("option name", ...)
Conf.bananas = parser.getOption("other option name", ...)
object Conf extends ScallopConf(List("-a","3","-b","5","tree")) {
val apples = opt[Int]("apples").map(a => if (a > 3) "plenty" else "few").orElse(Some("zero"))
val bananas = opt[Int]("bananas").map(3+)
val name = trailArg[String]()
verify
}
Conf.apples() // "few"
Conf.bananas() // 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment