Class CmdLineParser

  extended by

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


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


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


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

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.
AssertionError - if there is no short option, or if this option has already been used.


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

The short designator for the next argument. If there are no more arguments than the special designator CmdLineParser.EndOfOpts will be returned.
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.


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

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.


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

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


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

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

Copyright © ${year} The Apache Software Foundation