Changelog History
Page 1
-
v4.0.0 Changes
November 29, 2020π 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
-
v4.0.0-RC2 Changes
December 27, 2018π See http://eed3si9n.com/scopt4
-
v4.0.0-RC1
December 27, 2018 -
v3.7.1 Changes
December 13, 2018scopt 3.7.1 is cross built for Scala 2.10, 2.11, 2.12, 2.13.0, (2.13.0-M5), JS 0.6, and Native 0.3.
- scopt 3.7.1 is built using JDK 8.
- π Fixes hidden commands are displayed in usage #203 by @ozeebee
- β Adds typeclass instance for parsing URL #206 by @aaabramov
- β Adds overload for
version
andhelp
with long and short options #213 by @dani909 - β‘οΈ Other build updates from @xuwei-k, @SethTisue, and @ashawley
20 Kenji Yoshida (xuwei-k) 6 Eugene Yokota 1 Dale Wijnand 1 Denys Shabalin 1 Aaron S. Hawley 1 Seth Tisue 1 dani09 1 ozeebee 1 Brett Randall 1 Andrii Abramov
-
v3.7.0 Changes
August 25, 2017scopt 3.7.0 is cross built for Scala 2.10, 2.11, 2.12, 2.13.0-M2, JS 0.6, and Native 0.3.
withFallback
π Options now support a fallback value.
val parser = new scopt.OptionParser[Unit]("scopt") { head("scopt", "3.x") opt[String]("stringValue").required().withFallback(() =\> "someFallback") .foreach( x =\> stringValue = x ) help("help") }
This feature was contributed by @mpollmeier in #150
more exposure
π¦ Exposes values and methods such
name
,getMinOccurs
,getMaxOccurs
,isHidden
,desc
,shortOpt
, andvalueName
. #138 by @rhpvorderman -
v3.6.0 Changes
June 02, 2017π Scala.js support
π Scala.js support was added by @aappddeevv in #137.
Scala Native
π Scala Native support was added by @Duhemm in #141
π bug fixes and minor enhancements
-
v3.5.0 Changes
June 12, 2016π₯ breaking changes
two-column rendering
0οΈβ£ scopt 3.5.0 introduces two-column rendering for the usage text, which is enabled by default:
scopt 3.x Usage: scopt [update] [options] [<file>...] -f, --foo <value> foo is an integer property -o, --out <file> out is a required file property Command: update [options] update is a command. --xyz <value> xyz is a boolean property
This is a bit more compact compared to the previous (one-column) rendering that looked like this:
scopt 3.x Usage: scopt [update] [options] [<file>...] -f <value> | --foo <value> foo is an integer property -o <file> | --out <file> out is a required file property Command: update [options] update is a command. --xyz <value> xyz is a boolean property
You can switch back to the one-column rendering as follows:
override def renderingMode = scopt.RenderingMode.OneColumn
This feature was contributed by @Jibbers42 as #109.
-
v3.4.0 Changes
June 12, 2016π support for optional equal sign
π Given a parser like this:
val intParser1 = new scopt.OptionParser[Config]("scopt") { head("scopt", "3.x") opt[Int]('f', "foo") action { (x, c) => c.copy(intValue = x) } help("help") }
scopt 3.4.0 accepts all of the following options:
--foo 1
--foo:1
--foo=1
This was contributed as #87 by @maizy.
terminate
scopt 3.4.0 adds a termination hanlder called
terminate(exitState: Either[String, Unit])
. Override this method to prevent scopt from callingsys.exit(0)
on--help
or--version
.This was contributed as #74 by @metasim.
π other minor fixes and enhancements
- β Adds
Read[Seq[(K,V)]]
, which parseskey=1,key=2
asList("key" -> "1","key" -> "2")
. #70 by @sonenko - β Adds
Read[InetAddress]
, which parses an IP address usingjava.net.InetAddress.getByName
. #79 by @alexanderfefelov - β Adds
Read[Duration]
, which parses30s
asDuration("30s")
. #86 by @serejja - Increases the limit of
unbounded()
args. #83 by @billonahill - π Scala 2.9.x support is dropped.
-
v3.3.0 Changes
June 12, 2016comma-separated values
π scopt 3.3.0 adds support for comma-separated values that map to
Seq[A]
andMap[K, V]
(whereA
,K
andV
are instance ofRead
).- A
Seq[File]
accepts a string containing comma-separated values such as--jars foo.jar,bar.jar
- A
Map[String, String]
accepts a string containing comma-separated pairs like--kwargs key1=val1,key2=val2
Here's how they can be used:
opt[Seq[File]]('j', "jars") valueName("<jar1>,<jar2>...") action { (x,c) => c.copy(jars = x) } text("jars to include") opt[Map[String,String]]("kwargs") valueName("k1=v1,k2=v2...") action { (x, c) => c.copy(kwargs = x) } text("other arguments")
- A
-
v3.2.0 Changes
June 12, 2016π₯ breaking changes
shorter error message
π¨ Instead of printing a wall of usage text on error, if
help("help")
option is defined, scopt 3.2.0 prints just the error message and suggests to "Try --help for more information."
βͺ This behavior can be reverted by overridingshowUsageOnError
.π¨ usage text prints to
Console.out
π¨ Usage text will print to
Console.out
instead ofConsole.err
when invoked as--help
. #24 reported by @Ceilican.π new features
hidden options
opt can now be
hidden()
.opt[Unit]("debug") hidden() action { (_, c) => c.copy(debug = true) } text("this option is hidden in the usage text")
π§ check configuration
To check consistency among the provided
opt
values, scopt 3.2.0 introducescheckConfig
.val parser = new scopt.OptionParser[Config]("scopt") { head("scopt", "3.x") opt[Unit]('k', "keepalive") action { (x, c) => c.copy(keepalive= true) } opt[Boolean]("xyz") action { (x, c) => c.copy(xyz = x) } text("xyz is a boolean property"), checkConfig { c => if (c.keepalive && c.xyz) failure("xyz cannot keep alive") else success } help("help") text("prints this usage text") }