Class

scopt

OptionParser

Related Doc: package scopt

Permalink

abstract case class OptionParser[C](programName: String) extends Product with Serializable

scopt.immutable.OptionParser is instantiated within your object, set up by an (ordered) sequence of invocations of the various builder methods such as opt method or arg method.

val parser = new scopt.OptionParser[Config]("scopt") {
  head("scopt", "3.x")
  opt[Int]('f', "foo") action { (x, c) =>
    c.copy(foo = x) } text("foo is an integer property")
  opt[File]('o', "out") required() valueName("") action { (x, c) =>
    c.copy(out = x) } text("out is a required file property")
  opt[(String, Int)]("max") action { case ((k, v), c) =>
    c.copy(libName = k, maxCount = v) } validate { x =>
    if (x._2 > 0) success else failure("Value  must be >0")
  } keyValueName("", "") text("maximum count for ")
  opt[Unit]("verbose") action { (_, c) =>
    c.copy(verbose = true) } text("verbose is a flag")
  note("some notes.\n")
  help("help") text("prints this usage text")
  arg[File]("...") unbounded() optional() action { (x, c) =>
    c.copy(files = c.files :+ x) } text("optional unbounded args")
  cmd("update") action { (_, c) =>
    c.copy(mode = "update") } text("update is a command.") children(
    opt[Unit]("not-keepalive") abbr("nk") action { (_, c) =>
      c.copy(keepalive = false) } text("disable keepalive"),
    opt[Boolean]("xyz") action { (x, c) =>
      c.copy(xyz = x) } text("xyz is a boolean property")
  )
}
// parser.parse returns Option[C]
parser.parse(args, Config()) map { config =>
  // do stuff
} getOrElse {
  // arguments are bad, usage message will have been displayed
}
Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. OptionParser
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new OptionParser(programName: String)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def arg[A](name: String)(implicit arg0: Read[A]): OptionDef[A, C]

    Permalink

    adds an argument invoked by an option without - or --.

    adds an argument invoked by an option without - or --.

    name

    name in the usage text

  5. def arguments: Seq[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def checkConfig(f: (C) ⇒ Either[String, Unit]): OptionDef[Unit, C]

    Permalink

    adds final check.

  8. def checks: Seq[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def cmd(name: String): OptionDef[Unit, C]

    Permalink

    adds a command invoked by an option without - or --.

    adds a command invoked by an option without - or --.

    name

    name of the command

  11. def commands: Seq[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def errorOnUnknownArgument: Boolean

    Permalink
  14. def failure(msg: String): Either[String, Unit]

    Permalink

    call this to express failure in custom validation.

  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  17. def head(xs: String*): OptionDef[Unit, C]

    Permalink

    adds usage text.

  18. def header: String

    Permalink
  19. def heads: Seq[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  20. def help(name: String): OptionDef[Unit, C]

    Permalink

    adds an option invoked by --name that displays usage text and exits.

    adds an option invoked by --name that displays usage text and exits.

    name

    name of the option

  21. val helpOptions: ListBuffer[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. def makeDef[A](kind: OptionDefKind, name: String)(implicit arg0: Read[A]): OptionDef[A, C]

    Permalink
    Attributes
    protected
  24. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  25. def nonArgs: Seq[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  26. def note(x: String): OptionDef[Unit, C]

    Permalink

    adds usage text.

  27. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. def opt[A](x: Char, name: String)(implicit arg0: Read[A]): OptionDef[A, C]

    Permalink

    adds an option invoked by -x value or --name value.

    adds an option invoked by -x value or --name value.

    x

    name of the short option

    name

    name of the option

  30. def opt[A](name: String)(implicit arg0: Read[A]): OptionDef[A, C]

    Permalink

    adds an option invoked by --name x.

    adds an option invoked by --name x.

    name

    name of the option

  31. val options: ListBuffer[OptionDef[_, C]]

    Permalink
    Attributes
    protected
  32. def parse(args: Seq[String], init: C): Option[C]

    Permalink

    parses the given args.

  33. def parse(args: Seq[String])(implicit ev: Zero[C]): Boolean

    Permalink

    parses the given args.

    parses the given args.

    returns

    true if successful, false otherwise

  34. val programName: String

    Permalink
  35. def reportError(msg: String): Unit

    Permalink
  36. def reportWarning(msg: String): Unit

    Permalink
  37. def showHeader(): Unit

    Permalink
  38. def showTryHelp(): Unit

    Permalink
  39. def showUsage(): Unit

    Permalink
  40. def showUsageAsError(): Unit

    Permalink
  41. def showUsageOnError: Boolean

    Permalink
  42. def success: Either[String, Unit]

    Permalink

    call this to express success in custom validation.

  43. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  44. def terminate(exitState: Either[String, Unit]): Unit

    Permalink
  45. def usage: String

    Permalink
  46. def version(name: String): OptionDef[Unit, C]

    Permalink

    adds an option invoked by --name that displays header text and exits.

    adds an option invoked by --name that displays header text and exits.

    name

    name of the option

  47. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped