File: 3.0.0.markdown

package info (click to toggle)
scopt 3.5.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 312 kB
  • sloc: xml: 45; makefile: 13
file content (40 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## all new scopt 3.0

scopt 3.0 was rewritten from scratch to clean up the API:

    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")
      arg[File]("<file>...") unbounded() optional() action { (x, c) =>
        c.copy(files = c.files :+ x) } text("optional unbounded args")
    }

### polymorphic opt/arg

Both `opt[A]` and `arg[A]` take a type parameter of `A: Read`. Out of the box, `Unit`, `Int`, `Long`, `Double`, `String`, `Boolean`, `BigInt`, `BigDecimal`, `java.io.File`, `java.net.URI`, `java.util.Calendar` are supported. Key=value parameters are expressed as pair `(A1, A2)`.

### occurrences and custom validation

Occurrences can be specified using the fluent interface:

    opt[File]('o', "out") required()
    arg[File]("<file>...") optional() unbounded()

Custom validation logic:

    opt[Int]('f', "foo") validate { x =>
      if (x > 0) success else failure("Option --foo must be >0") } 

### commands

scopt3 supports multiple levels of command structure:

    cmd("backend") text("commands to manipulate backends:\n") action { (x, c) =>
      c.copy(flag = true) } children {
      cmd("update") children {
        arg[String]("<a>") action { (x, c) => c.copy(a = x) } 
      }     
    }

See [scopt](https://github.com/scopt/scopt) for more details.