implicit.ly

Scala software, hot off the presses

scopt 2.0.1

  • Fixes Unit opt. #1

scopt is a little command line options parsing library.

via herald

Filed under  //   scopt  

scopt 2.0.0

immutable parser

In addition to the mutable parser from scopt 1.x, 2.0.0 adds an immutable parser.

val parser = new scopt.immutable.OptionParser[Config]("scopt", "2.x") { def options = Seq(
  intOpt("f", "foo", "foo is an integer property") { (v: Int, c: Config) => c.copy(foo = v) },
  opt("o", "output", "output") { (v: String, c: Config) => c.copy(bar = v) },
  booleanOpt("xyz", "xyz is a boolean property") { (v: Boolean, c: Config) => c.copy(xyz = v) },
  keyValueOpt("l", "lib", "<libname>", "<filename>", "load library <libname>")
    { (key: String, value: String, c: Config) => c.copy(libname = key, libfile = value) },
  keyIntValueOpt(None, "max", "<libname>", "<max>", "maximum count for <libname>")
    { (key: String, value: Int, c: Config) => c.copy(maxlibname = key, maxcount = value) },
  arg("<file>", "some argument") { (v: String, c: Config) => c.copy(whatnot = v) }
) }
// parser.parse returns Option[C]
parser.parse(args, Config()) map { config =>
  // do stuff
} getOrElse {
  // arguments are bad, usage message will have been displayed
}

Instead of updating the config object in-place, the immutable parser expects call back functions that takes a config object and returns a new one.

scopt is a little command line options parsing library.

via herald

Filed under  //   scopt  

scopt 1.1.2

  • Cross built against Scala 2.9.1, 2.9.0-1, and 2.8.1.

scopt is a little command line options parsing library.

Filed under  //   Scala 2.8.1   Scala 2.9.0-1   Scala 2.9.1   com.github.scopt   scopt  

scopt 1.1.0

  • Adds argOpt and arglistOpt method for optional arguments.

scopt is a little command line options parsing library.

Filed under  //   Scala 2.7.7   Scala 2.8.0   Scala 2.8.1   Scala 2.9.0-1   com.github.scopt   scopt  

scopt 1.0.0

hello, world

This is the initial release of scopt, a little command line parsing library.

You can customize an OptionParser by passing in functions to process each option or argument.

val parser = new OptionParser("scopt") {
  intOpt("f", "foo", "foo is an integer property", {v: Int => config.foo = v})
  opt("o", "output", "<file>", "output is a string property", {v: String => config.bar = v})
  booleanOpt("xyz", "xyz is a boolean property", {v: Boolean => config.xyz = v})
  keyValueOpt("l", "lib", "<libname>", "<filename>", "load library <libname>",
    {(key: String, value: String) => { config.libname = key; config.libfile = value } })
  arg("<singlefile>", "<singlefile> is an argument", {v: String => config.whatnot = v})
  // arglist("<file>...", "arglist allows variable number of arguments",
  //   {v: String => config.files = (v :: config.files).reverse })
}
if (parser.parse(args)) {
   // do stuff
}
else {
  // arguments are bad, usage message will have been displayed
}

It handles various kinds of options such as optional, required, and key-value. From the above, it also automatically generates the usage text as follows:

Usage: scopt [options] <filename>

  -f <value> | --foo <value>
        foo is an integer property
  -o <file> | --output <file>
        output is a string property
  --xyz <value>
        xyz is a boolean property
  -l:<libname>=<filename> | --lib:<libname>=<filename>
        load library <libname>
  <singlefile>
        <singlefile> is an argument

scopt is a little command line options parsing library.

Filed under  //   Scala 2.7.7   Scala 2.8.0   Scala 2.8.1   Scala 2.9.0-1   com.github.scopt   scopt