Skip to content
biocyberman edited this page Jan 29, 2013 · 5 revisions

This article describes the most basic usage of Scallop - it is intended to help you get started quickly.

import org.rogach.scallop._

class Conf(arguments: Seq[String]) extends ScallopConf(arguments) {
  val apples = opt[Int]("apples", required = true)
  val bananas = opt[Int]("bananas")
  val name = trailArg[String]()
}

object Main {
  def main(args: Array[String]) {
    val conf = new Conf(args)
    println("apples are: " + conf.apples())
  }
}

This snippet above defined simple configuration, that will parse argument lines like this:

--apples 4 --bananas 10 bigBunny
-a 4 -b 10 bigBunny

Accessing options is simple:

conf.apples() should equal (4)
conf.bananas.get should equal (Some(10))
conf.name() should equal ("bigBunny")

That's it - completely type safe!

Also, you can pass the resulting object into some functions as an argument:

object Conf extends ScallopConf(arguments) {
  // ... options ...
}
def someInternalFunc(conf:Conf.type) {
  conf.count() should equal (4)
}
someInternalFunc(Conf)

Clone this wiki locally