Helper for simplified args4j parsing
Scala Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.settings
project
src/main/scala/com/bizo/util/args4j
.gitignore
.project
.travis.yml
LICENSE.txt
build.sbt
build.sh
init-sbt
package.json
readme.md

readme.md

args4j-helpers

Build Status

Simple helper for command-line parsing using args4j.

Args4j is a fantastic parsing library, but there's typically a lot of boilerplate for dealing with printing usage and dealing with parse errors.

This library encapsulates typical option parsing error handling:

  • If help (provided via OptionWithHelp base trait bound to --help and -h) is requested, print usage information to stderr, exit with code 0.
  • If a required option is missing (required=true), print usage information to stderr, exit with code 1 (unless help was requested).

Usage

Define your options class normally, extending OptionsWithHelp

class MyOptions extends OptionsWithHelp {
  @Option(name="--blah", aliases=Array("-b"), usage="some val", metaVar="BLAH")
  var blah: Int = 0
}

retrieving/parsing becomes a single line

import OptionHelper.optionsOrExit

def main(args: Array[String]) {
  val options = optionsOrExit(args, new MyOptions)

  println(s"blah is ${options.blah}")
}

License

Apache 2 License