OptionParser

abstract class OptionParser[C](programName: String) extends OptionDefCallback[C]
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.OptionParserConfig {
head("scopt", "4.x")
optInt.action( (x, c) =>
c.copy(foo = x) ).text("foo is an integer property")
optFile.required().valueName("").
action( (x, c) => c.copy(out = x) ).
text("out is a required file property")
opt(String, Int).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 ")
optSeq[File].valueName(",...").action( (x,c) =>
c.copy(jars = x) ).text("jars to include")
optMap[String,String].valueName("k1=v1,k2=v2...").action( (x, c) =>
c.copy(kwargs = x) ).text("other arguments")
optUnit.action( (_, c) =>
c.copy(verbose = true) ).text("verbose is a flag")
optUnit.hidden().action( (_, c) =>
c.copy(debug = true) ).text("this option is hidden in the usage text")
help("help").text("prints this usage text")
argFile.unbounded().optional().action( (x, c) =>
c.copy(files = c.files :+ x) ).text("optional unbounded args")
note("some notes.".newline)
cmd("update").action( (, c) => c.copy(mode = "update") ).
text("update is a command.").
children(
optUnit.abbr("nk").action( (, c) =>
c.copy(keepalive = false) ).text("disable keepalive"),
optBoolean.action( (x, c) =>
c.copy(xyz = x) ).text("xyz is a boolean property"),
optUnit.hidden().action( (_, c) =>
c.copy(debug = true) ).text("this option is hidden in the usage text"),
checkConfig( c =>
if (c.keepalive && c.xyz) failure("xyz cannot keep alive")
else success )
)
}
// parser.parse returns Option[C]
parser.parse(args, Config()) match {
case Some(config) =>
// do stuff
case None =>
// arguments are bad, error message will have been displayed
}
}}}
class Object
trait Matchable
class Any

Value members

Methods

def showUsageOnError: Option[Boolean]
def reportError(msg: String): Unit
def reportWarning(msg: String): Unit
def terminate(exitState: Either[String, Unit]): Unit
def displayToOut(msg: String): Unit
def displayToErr(msg: String): Unit
def opt[A](name: String)(evidence$1: Read[A]): OptionDef[A, C]
adds an option invoked by --name x.
Value Params
name
name of the option
def opt[A](x: Char, name: String)(evidence$2: Read[A]): OptionDef[A, C]
adds an option invoked by -x value or --name value.
Value Params
name
name of the option
x
name of the short option
def note(x: String): OptionDef[Unit, C]
adds usage text.
def arg[A](name: String)(evidence$3: Read[A]): OptionDef[A, C]
adds an argument invoked by an option without - or --.
Value Params
name
name in the usage text
def cmd(name: String): OptionDef[Unit, C]
adds a command invoked by an option without - or --.
Value Params
name
name of the command
def help(name: String): OptionDef[Unit, C]
adds an option invoked by --name that displays usage text and exits.
Value Params
name
name of the option
def help(x: Char, name: String): OptionDef[Unit, C]
adds an option invoked by -x or --name that displays usage text and exits.
Value Params
name
name of the option
x
name of the short option
def version(name: String): OptionDef[Unit, C]
adds an option invoked by --name that displays header text and exits.
Value Params
name
name of the option
def version(x: Char, name: String): OptionDef[Unit, C]
adds an option invoked by -x or --name that displays header text and exits.
Value Params
name
name of the option
x
name of the short option
def checkConfig(f: C => Either[String, Unit]): OptionDef[Unit, C]
adds final check.
def usage: String
def success: Either[String, Unit]
call this to express success in custom validation.
def failure(msg: String): Either[String, Unit]
call this to express failure in custom validation.
protected def makeDef[A](kind: OptionDefKind, name: String)(evidence$4: Read[A]): OptionDef[A, C]
def parse(args: Seq[String], init: C): Option[C]
parses the given args.

Fields

protected val options: ListBuffer[OptionDef[, C]]