com.telelogic.cs.api
Class OptionParser

java.lang.Object
  extended by com.telelogic.cs.api.OptionParser

public class OptionParser
extends java.lang.Object

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
 

Since:
4.7 06

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

parse

public static OptionParser parse(java.lang.String[] args)
Parses a list of strings to find any option/value pairs.

Parameters:
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.
Returns:
the OptionParser that contain the options and arguments that were parsed.

getArgs

public java.lang.String[] getArgs()
Gets all the arguments, i.e., all the strings that weren't options or option values.

Returns:
array of arguments that were parsed.

getOptions

public 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.

Returns:
map for option names, including the leading "-", to their values.

getOption

public java.lang.String getOption(java.lang.String optionName)
Gets a specific option by name.

Parameters:
optionName - name of the option to get, including the leading "-".
Returns:
the value for the named option, or null if the option wasn't found.


© Copyright IBM Corporation 2000, 2009
US Government Users Restricted Rights--Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Notices