Scopt v4.0.0 Release Notes
Release Date: 2020-11-29 // over 2 years 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
-
π See http://eed3si9n.com/scopt4