scopt 4.0.0 is cross published for the following build matrix:
Scala |
JVM |
JS (1.x) |
JS (0.6.x) |
Native (0.4.0-M2) |
Native (0.3.x) |
3.0.0-M2 |
✅ |
✅ |
n/a |
n/a |
n/a |
3.0.0-M1 |
✅ |
✅ |
n/a |
n/a |
n/a |
2.13.x |
✅ |
✅ |
✅ |
n/a |
n/a |
2.12.x |
✅ |
✅ |
✅ |
n/a |
n/a |
2.11.x |
✅ |
✅ |
✅ |
✅ |
✅ |
Here's how functional DSL looks like in scopt 4:
import scopt.OParser
val builder = OParser.builder[Config]
val parser1 = {
import builder._
OParser.sequence(
programName("scopt"),
head("scopt", "4.x"),
// option -f, --foo
opt[Int]('f', "foo")
.action((x, c) => c.copy(foo = x))
.text("foo is an integer property"),
// more options here...
)
}
// OParser.parse returns Option[Config]
OParser.parse(parser1, args, Config()) match {
case Some(config) =>
// do something
case _ =>
// arguments are bad, error message will have been displayed
}
Instead of calling methods on OptionParser
, the functional DSL first creates a builder based on your specific Config
datatype, and calls opt[A](...)
functions that returns OParser[A, Config]
.
These OParser[A, Config]
parsers can be composed using OParser.sequence(...)
.