Created
April 8, 2012 11:34
-
-
Save Rogach/2336746 to your computer and use it in GitHub Desktop.
scallop examples 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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