abstract case classOptionParser[C](programName: String) extends Product with Serializable
scopt.immutable.OptionParser is instantiated within your object,
set up by an (ordered) sequence of invocations of
the various builder methods such as
opt method or
arg method.
scopt.immutable.OptionParser is instantiated within your object,
set up by an (ordered) sequence of invocations of
the various builder methods such as
opt method or
arg method.
val parser = new scopt.OptionParser[Config]("scopt") {
head("scopt", "3.x")
opt[Int]('f', "foo") action { (x, c) =>
c.copy(foo = x) } text("foo is an integer property")
opt[File]('o', "out") required() valueName("") action { (x, c) =>
c.copy(out = x) } text("out is a required file property")
opt[(String, Int)]("max") action { case ((k, v), c) =>
c.copy(libName = k, maxCount = v) } validate { x =>if (x._2 > 0) success else failure("Value must be >0")
} keyValueName("", "") text("maximum count for ")
opt[Unit]("verbose") action { (_, c) =>
c.copy(verbose = true) } text("verbose is a flag")
note("some notes.\n")
help("help") text("prints this usage text")
arg[File]("...") unbounded() optional() action { (x, c) =>
c.copy(files = c.files :+ x) } text("optional unbounded args")
cmd("update") action { (_, c) =>
c.copy(mode = "update") } text("update is a command.") children(
opt[Unit]("not-keepalive") abbr("nk") action { (_, c) =>
c.copy(keepalive = false) } text("disable keepalive"),
opt[Boolean]("xyz") action { (x, c) =>
c.copy(xyz = x) } text("xyz is a boolean property")
)
}
// parser.parse returns Option[C]
parser.parse(args, Config()) map { config =>// do stuff
} getOrElse {
// arguments are bad, usage message will have been displayed
}
scopt.immutable.OptionParser
is instantiated within your object, set up by an (ordered) sequence of invocations of the various builder methods such asopt
method orarg
method.