Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
simple scala command line options parsing
tag: 1.1.0

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.0.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.


  • added -x:key=value option
  • updated usage text style
  • added maven and sbt builds
  • added ScalaTest test cases
  • added arguments which then are displayed in help
  • minor refactoring of names; opt and arg for options and args
  • updated sbt and maven to build against Scala 2.8.0
  • added option that does not have short option
Something went wrong with that request. Please try again.