org.apache.pig.tools.cmdline
Class CmdLineParser

java.lang.Object
  extended by org.apache.pig.tools.cmdline.CmdLineParser

public class CmdLineParser
extends Object


Nested Class Summary
static class CmdLineParser.ValueExpected
           
 
Field Summary
static char EndOfOpts
           
 
Constructor Summary
CmdLineParser(String[] args)
           
 
Method Summary
 char getNextOpt()
          Get the next option.
 String[] getRemainingArgs()
          Get any remaining arguments.
 Integer getValInt()
          Get the value, as an Integer.
 String getValStr()
          Get the value, as a string.
 void registerOpt(char c, String s, CmdLineParser.ValueExpected ve)
          Register a command line option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EndOfOpts

public static final char EndOfOpts
See Also:
Constant Field Values
Constructor Detail

CmdLineParser

public CmdLineParser(String[] args)
Parameters:
args - String array of arguments passed to the program.
Method Detail

registerOpt

public void registerOpt(char c,
                        String s,
                        CmdLineParser.ValueExpected ve)
Register a command line option.

Parameters:
c - Single character designator for this option. It cannot be '-'.
s - Full word designator for this option. This can be null, in which case no long designator will exist for this option.
ve - If REQUIRED, a value will be expected with this option. If OPTIONAL a value will be accepted if it is seen.
Throws:
AssertionError - if there is no short option, or if this option has already been used.

getNextOpt

public char getNextOpt()
                throws ParseException
Get the next option.

Returns:
The short designator for the next argument. If there are no more arguments than the special designator CmdLineParser.EndOfOpts will be returned.
Throws:
ParseException - if an unknown option is found or an option that expects a value does not have one or a value that does not expect a value does have one.

getRemainingArgs

public String[] getRemainingArgs()
Get any remaining arguments.

Returns:
In general this function will null. Only if the caller passed a '-' or '--' followed by other arguments. In that case the remainder of the args array will be returned.

getValStr

public String getValStr()
Get the value, as a string.

Returns:
The value associated with the current option. If there is no value, then null will be returned.

getValInt

public Integer getValInt()
                  throws NumberFormatException
Get the value, as an Integer.

Returns:
The value associated with the current option. If there is not value, then null will be returned.
Throws:
NumberFormatException - if the value cannot be converted to an integer.


Copyright © ${year} The Apache Software Foundation