Long name for this option (--long_name on the command line)
Short name for this option (-short_name on the command line)
Default value for this option
Description of the parameter (used in help message)
Other flags that this option implicitly enables
Other flags that this option implicitly disables
Other options that are required to be set when using this options
Whether or not this option is exclusive and cannot be used with any other options (e.g. like --help where it prints the help message and exits)
A method that takes the String value and returns a boolean indicating if the argument value is valid
Get the value
Get the value
This calls Option.get on the underlying value so an exception will be thrown if the value is not set.
A no-op default parsing method
Reset the value to the default
Validate the parsed value using the validate argument passed in on the constructor
Validate the parsed value using the validate argument passed in on the constructor
The value attached to this command line option (wrapped in an Option)
The value attached to this command line option (wrapped in an Option)
A command line option that takes a string argument
Examples
object MyApp extends OptParse { // Basic string argument using a default long name of --name and short name of -n val name = StrOpt() // Example with all available options instead of relying on the defaults val message = BoolOpt( long="message", // Long name to use (--message) short="m", // Short name to use (-m) default="Hello", // Default value desc="Message to print", // Help message description enables=Nil, // Other flags to enable if this one is enabled (single option or a Seq of options) disables=Nil, // Other flags to disable if this one is enabled (single option or a Seq of options) invalidWith=Nil, // Other options this flag is invalid with (they cannot be set) validWith=Nil, // Other options that are required with this flag exclusive=false, // Other options can be set when this option is set validate="^[a-zA-Z ,]+$" // Use a regex for validation via an implicit that converts it to: (String) => Boolean ) def main(args:Array[String]) { parse(args) // getOrElse is available via an implicit from OptVal to Option[String] println(message+" "+name.getOrElse("Anonymous")) } }