Scopt v4.0.0 Release Notes

Release Date: 2020-11-29 // about 1 year ago
  • πŸ‘€ scopt is a little command line options parsing library. See https://eed3si9n.com/scopt4 for the details.

    πŸ— scopt 4.0.0 is cross published to the following build matrix:

    Scala Version JVM JS (1.x) JS (0.6.x) Native (0.4.x) 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 βœ… βœ… βœ… βœ… βœ…

    Functional DSL

    scopt 4.0.0 brings a new Functional DSL.

    import scopt.OParserval 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 somethingcase \_ =\>// arguments are bad, error message will have been displayed}
    

    Abstracting over effects

    πŸ“œ If your application requires parsing arguments while not producing output directly, you may wish to intercept the side effects. Use OParser.runParser(...) to do so:

    // OParser.runParser returns (Option[Config], List[OEffect])OParser.runParser(parser1, args, Config()) match { case (result, effects) =\>OParser.runEffects(effects, new DefaultOEffectSetup { // override def displayToOut(msg: String): Unit = Console.out.println(msg)// override def displayToErr(msg: String): Unit = Console.err.println(msg)// override def reportError(msg: String): Unit = displayToErr("Error: " + msg)// override def reportWarning(msg: String): Unit = displayToErr("Warning: " + msg)// ignore terminateoverride def terminate(exitState: Either[String, Unit]): Unit = () }) result match { Some(config) =\>// do somethingcase \_ =\>// arguments are bad, error message will have been displayed } }
    

    πŸ“œ Object-oriented DSL, immutable parsing

    πŸ’… We kept the source-compatibility with scopt 3.x style object-oriented DSL. The following should work without modification:

    val parser = new scopt.OptionParser[Config]("scopt") { head("scopt", "4.x") opt[Int]('f', "foo") .action((x, c) =\> c.copy(foo = x)) .text("foo is an integer property") opt[File]('o', "out") .required() .valueName("\<file\>") .action((x, c) =\> c.copy(out = x)) .text("out is a required file property") }// parser.parse returns Option[C]parser.parse(args, Config()) match { case Some(config) =\>// do stuffcase None =\>// arguments are bad, error message will have been displayed}
    

    Participation

    πŸ”€ According to git shortlog -sn --no-merges v3.7.1...v4.0.0, scopt 4.0.0 is brought to you by 12 contributors. Thanks!

        28 Eugene Yokota (eed3si9n)
        12 Kenji Yoshida (xuwei-k)
         6 Christophe Vidal
         4 Morgen Peschke
         2 Sasa Zejnilovic
         1 Lorenzo Gabriele
         1 Martynas Mickevičius
         1 Sean Sullivan
         1 aappddeevv
         1 Enver Osmanov
         1 Daniel
         1 Hanns Holger Rutz
         1 Jeff Shaw
    

Previous changes from v4.0.0-RC2