object Parser
Low-level parsing functionality. See ArgParser for a user-friendly API.
- Alphabetic
- By Inheritance
- Parser
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- case class ParamDef(names: Seq[String], parseAndSet: (String, Option[String]) => ParamResult, missing: () => Unit, isFlag: Boolean, repeatPositional: Boolean, absorbRemaining: Boolean) extends Product with Serializable
A parameter definition is the low-level building block to define the grammar of a command-line, and its functionality.
A parameter definition is the low-level building block to define the grammar of a command-line, and its functionality.
ParamDefs associate parameter names to actions that are invoked by Parser.parse() in certain situations.
- names
All names that may be used by this parameter. If a name starts with
-
, it is considered a "named" parameter, otherwise it is considered a "positional" parameter. Arguments associated to named parameters may appear in any order on the command line, as long as they are prefixed by the parameter's name. Positional parameters are given arguments in the order they appear in.- parseAndSet
A function that is invoked anytime this parameter is encountered on the command line. In case of a named param, the first element is the actual name used, and the second element is the argument or None if no argument followed. In case of a position param, the parameter's first name is given and the argument value is always defined.
- missing
A function that is invoked if this parameter has not been encountered at all.
- isFlag
Indicates if this named parameter is a flag, i.e. one that never accepts an argument. In case its name is encountered, its value is set to "true". Has no effect on positional parameters.
- repeatPositional
If this is a positional parameter, it will be the parser will repeat it indefinitely.
- absorbRemaining
Treat all subsequent parameters as positionals, regardless of their name. This can be useful for constructing nested commands.
- sealed trait ParamResult extends AnyRef
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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def parse(params: Seq[ParamDef], args: Seq[String], reportUnknown: (String) => Unit): Boolean
Parse command line arguments according to some given parameter definition.
Parse command line arguments according to some given parameter definition.
The parser works in two passes. 1. the first pass goes over all actual arguments and groups them into positional and named ones (and also detects any unkown arguments) 2. the second pass then iterates over all parameter definitions, looks up the corresponding value from the previous pass, and calls the relevant functions of the parameter defintion
Delegating parameter invocation to a second pass allows for them to be evaluated in order of defnition, rather than order of appearance on the command line. This is important to allow "breaking" parameters such as
--help
to be on a command line with other "side-effecting" params, but yet avoid executing part of the command line (of course this example assumes that the--help
parameter was defined before any others).- params
the sequence of parameter definitions
- args
the actual command-line arguments
- reportUnknown
a function invoked when an extranous argument is encountered. An extranous argument can be either an unknown named argument, or a superfluous positional argument
- returns
true if no Abort was encountered. Note that this does not necessarily imply failure or success. false otherwise
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- case object Abort extends ParamResult with Product with Serializable
- case object Continue extends ParamResult with Product with Serializable