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("Valuemust be >0" ) ). keyValueName("" , "" ). text("maximum count for" ) opt[Seq[File]]('j', "jars").valueName(", ).action( (x,c) => c.copy(jars = x) ).text("jars to include") opt[Map[String,String]]("kwargs").valueName("k1=v1,k2=v2...").action( (x, c) => c.copy(kwargs = x) ).text("other arguments") opt[Unit]("verbose").action( (_, c) => c.copy(verbose = true) ).text("verbose is a flag") opt[Unit]("debug").hidden().action( (_, c) => c.copy(debug = true) ).text("this option is hidden in the usage text") help("help").text("prints this usage text") arg[File]("..." ..." ).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( 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"), opt[Unit]("debug-update").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 }
- Alphabetic
- By Inheritance
- OptionParser
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new OptionParser(programName: String)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
arg[A](name: String)(implicit arg0: Read[A]): OptionDef[A, C]
adds an argument invoked by an option without
-or--.adds an argument invoked by an option without
-or--.- name
name in the usage text
-
def
arguments: Seq[OptionDef[_, C]]
- Attributes
- protected
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
checkConfig(f: (C) ⇒ Either[String, Unit]): OptionDef[Unit, C]
adds final check.
-
def
checks: Seq[OptionDef[_, C]]
- Attributes
- protected
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
cmd(name: String): OptionDef[Unit, C]
adds a command invoked by an option without
-or--.adds a command invoked by an option without
-or--.- name
name of the command
-
def
commands: Seq[OptionDef[_, C]]
- Attributes
- protected
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def errorOnUnknownArgument: Boolean
-
def
failure(msg: String): Either[String, Unit]
call this to express failure in custom validation.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
head(xs: String*): OptionDef[Unit, C]
adds usage text.
- def header: String
-
def
heads: Seq[OptionDef[_, C]]
- Attributes
- protected
-
def
help(name: String): OptionDef[Unit, C]
adds an option invoked by
--namethat displays usage text and exits.adds an option invoked by
--namethat displays usage text and exits.- name
name of the option
-
val
helpOptions: ListBuffer[OptionDef[_, C]]
- Attributes
- protected
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
makeDef[A](kind: OptionDefKind, name: String)(implicit arg0: Read[A]): OptionDef[A, C]
- Attributes
- protected
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nonArgs: Seq[OptionDef[_, C]]
- Attributes
- protected
-
def
note(x: String): OptionDef[Unit, C]
adds usage text.
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
opt[A](x: Char, name: String)(implicit arg0: Read[A]): OptionDef[A, C]
adds an option invoked by
-x valueor--name value.adds an option invoked by
-x valueor--name value.- x
name of the short option
- name
name of the option
-
def
opt[A](name: String)(implicit arg0: Read[A]): OptionDef[A, C]
adds an option invoked by
--name x.adds an option invoked by
--name x.- name
name of the option
-
val
options: ListBuffer[OptionDef[_, C]]
- Attributes
- protected
- def optionsForRender: List[OptionDef[_, C]]
-
def
parse(args: Seq[String], init: C): Option[C]
parses the given
args. -
def
parse(args: Seq[String])(implicit ev: Zero[C]): Boolean
parses the given
args.parses the given
args.- returns
trueif successful,falseotherwise
- val programName: String
- def renderOneColumnUsage: String
- def renderTwoColumnsUsage: String
- def renderUsage(mode: RenderingMode): String
- def renderingMode: RenderingMode
- def reportError(msg: String): Unit
- def reportWarning(msg: String): Unit
- def showHeader(): Unit
- def showTryHelp(): Unit
- def showUsage(): Unit
- def showUsageAsError(): Unit
- def showUsageOnError: Boolean
-
def
success: Either[String, Unit]
call this to express success in custom validation.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- def terminate(exitState: Either[String, Unit]): Unit
- def usage: String
- def usageExample: String
-
def
version(name: String): OptionDef[Unit, C]
adds an option invoked by
--namethat displays header text and exits.adds an option invoked by
--namethat displays header text and exits.- name
name of the option
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )