Version Matrix

scala-commandline

Test Workflow Release Notes Maven Central Apache License 2.0

A small state-monad-based command line parser library written in scala

build.sbt

libraryDependencies += "de.lolhens" %% "scala-commandline" % "0.3.1"

Example

case class Options(help: Boolean,
                   version: Boolean,
                   logLevel: Option[String],
                   decode: Boolean,
                   validate: Boolean,
                   params: Seq[String])

def main(args: Array[String]): Unit = {
  val options: Options = CommandLine(args) {
    for {
      default <- CommandLine.defaultOpts()
      /* shorthand for:
      empty <- CommandLine.isEmpty
      help <- CommandLine.opt("-h", "--help").flag
      version <- CommandLine.opt("--version").flag
      */
      logLevel <- CommandLine.opt("--loglevel").arg.map(_.lastOption)
      decode <- CommandLine.opt("-d", "--decode").flag
      validate <- CommandLine.opt("--validate").flag
      _ <- CommandLine.errorOnUnrecognizedOpts()
      params <- CommandLine.args
    } yield Options(
      help = default.empty || default.help,
      version = default.version,
      logLevel = logLevel,
      decode = decode,
      validate = validate,
      params = params
    )
  }
}

License

This project uses the Apache 2.0 License. See the file called LICENSE.