|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.telelogic.cs.api.OptionParser
public class OptionParser
A simple options parser which separates command line options from arguments. An option is any word that begins with a "-"; its value is the string immediately following it. All string that are not options or option values are considered arguments. This is most useful in script languages that don't have a built in option parsing mechanism--like JavaScript--but can also help to guarantee consistent option parsing between multiple script languages.
Example: the strings "-from", "100", "-to", "200", "duplicate", would be considered to have two options (-from=100 and -to=200) and one argument, "duplicate".
Trigger scripts are given the exact list of arguments to them. Scripts that want to be flexible in what they do can use this class to help parse more complicated arguments lists, e.g.:
var options = Packages.com.telelogic.cs.api.OptionParser.parse(args); var foo = options.getOption("-foo"); // handle option foo
Method Summary | |
---|---|
java.lang.String[] |
getArgs()
Gets all the arguments, i.e., all the strings that weren't options or option values. |
java.lang.String |
getOption(java.lang.String optionName)
Gets a specific option by name. |
java.util.Map<java.lang.String,java.lang.String> |
getOptions()
Gets all the options, i.e., the strings that started with a "-" and their values that followed. |
static OptionParser |
parse(java.lang.String[] args)
Parses a list of strings to find any option/value pairs. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static OptionParser parse(java.lang.String[] args)
args
- an array of strings. Each one starting with a dash ("-") is assumed to
be an option, followed by its value. If an option is repeated, the last
value is used. All leftover strings are considered arguments.
OptionParser
that contain the options
and arguments that were parsed.public java.lang.String[] getArgs()
public java.util.Map<java.lang.String,java.lang.String> getOptions()
public java.lang.String getOption(java.lang.String optionName)
optionName
- name of the option to get, including the leading "-".
null
if the
option wasn't found.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |