simple scala command line options parsing
Switch branches/tags
Nothing to show
Pull request Compare This branch is 5 commits behind jstrachan:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


scopt is a little command line options parsing library.

Its based on the code from Tim Perrett which his based on Aaron Harnly's code mentioned in this thread and this thread which is available as a gist or here.

If you prefer the Annotation approach

Since hacking on scopt I've now moved to the Annotation Approach via Karaf you might like to check that out if you find limitations in scopt.


Create an OptionParser and customise it with the options you need, passing in functions to process each option or argument.

val parser = new OptionParser("scopt") {
  intOpt("f", "foo", "foo is an integer property", {v: Int => = v})
  opt("o", "output", "<file>", "output is a string property", {v: String => = v})
  booleanOpt("xyz", "xyz is a boolean property", {v: Boolean => = 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

The above generates the following usage text:

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> is an argument Nexus

val scopt = "com.github.scopt" %% "scopt" % "1.1.0"
val scalaToolsNexusSnapshots = "Scala Tools Nexus Snapshots" at ""
val scalaToolsNexusReleases  = "Scala Tools Nexus Releases" at ""


You should be able to use sbt to build scopt.


Do whatever you like with it :), or use MIT License.


See notes.