com.openexchange.admin.console
Class CLIParser

java.lang.Object
  extended by com.openexchange.admin.console.CLIParser
Direct Known Subclasses:
AdminParser

public class CLIParser
extends Object

CLIParser - The command-line parser.

Author:
Thorben Betten

Constructor Summary
CLIParser()
          Initializes a new non-strict CLIParser.
CLIParser(boolean posix)
          Initializes a new CLIParser.
 
Method Summary
 CLIOption addBooleanOption(char shortForm, String longForm)
          Convenience method for adding a boolean option.
 CLIOption addBooleanOption(String longForm)
          Convenience method for adding a boolean option.
 CLIOption addDoubleOption(char shortForm, String longForm)
          Convenience method for adding a double option.
 CLIOption addDoubleOption(String longForm)
          Convenience method for adding a double option.
 CLIOption addIntegerOption(char shortForm, String longForm)
          Convenience method for adding an integer option.
 CLIOption addIntegerOption(String longForm)
          Convenience method for adding an integer option.
 CLIOption addLongOption(char shortForm, String longForm)
          Convenience method for adding a long integer option.
 CLIOption addLongOption(String longForm)
          Convenience method for adding a long integer option.
 CLIOption addOption(CLIOption opt)
          Adds the specified option to the list of options.
 CLIOption addSettableBooleanOption(String longForm)
          Convenience method for adding a settable boolean option.
 CLIOption addStringOption(char shortForm, String longForm)
          Convenience method for adding a string option.
 CLIOption addStringOption(String longForm)
          Convenience method for adding a string option.
 Object getOptionValue(CLIOption o)
          Gets given option's value.
 Object getOptionValue(CLIOption o, Object def, boolean remove)
          Gets given option's value.
 Collection<Object> getOptionValues(CLIOption option)
          Gets the parsed values of all occurrences of given option, or an empty collection if the option was not set.
 String[] getRemainingArgs()
           
 void parse(String[] argv)
          Parses specified command line.
 void parse(String[] argv, Locale locale)
          Parses specified command line.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLIParser

public CLIParser()
Initializes a new non-strict CLIParser.


CLIParser

public CLIParser(boolean posix)
Initializes a new CLIParser.

Parameters:
posix - true to strictly parse command line in POSIX notation; otherwise false
Method Detail

addOption

public CLIOption addOption(CLIOption opt)
Adds the specified option to the list of options.

Parameters:
opt - The option to add
Returns:
The added option

addStringOption

public CLIOption addStringOption(char shortForm,
                                 String longForm)
Convenience method for adding a string option.

Parameters:
shortForm - The option's short form
longForm - The option's long form
Returns:
The added option

addStringOption

public CLIOption addStringOption(String longForm)
Convenience method for adding a string option.

Parameters:
longForm - The option's long form
Returns:
The added option

addSettableBooleanOption

public CLIOption addSettableBooleanOption(String longForm)
Convenience method for adding a settable boolean option.

Parameters:
longForm - The option's long form
Returns:
The added option

addIntegerOption

public CLIOption addIntegerOption(char shortForm,
                                  String longForm)
Convenience method for adding an integer option.

Parameters:
shortForm - The option's short form
longForm - The option's long form
Returns:
The added option

addIntegerOption

public CLIOption addIntegerOption(String longForm)
Convenience method for adding an integer option.

Parameters:
longForm - The option's long form
Returns:
The added option

addLongOption

public CLIOption addLongOption(char shortForm,
                               String longForm)
Convenience method for adding a long integer option.

Parameters:
shortForm - The option's short form
longForm - The option's long form
Returns:
The added option

addLongOption

public CLIOption addLongOption(String longForm)
Convenience method for adding a long integer option.

Parameters:
longForm - The option's long form
Returns:
The added option

addDoubleOption

public CLIOption addDoubleOption(char shortForm,
                                 String longForm)
Convenience method for adding a double option.

Parameters:
shortForm - The option's short form
longForm - The option's long form
Returns:
The added option

addDoubleOption

public CLIOption addDoubleOption(String longForm)
Convenience method for adding a double option.

Parameters:
longForm - The option's long form
Returns:
The added option

addBooleanOption

public CLIOption addBooleanOption(char shortForm,
                                  String longForm)
Convenience method for adding a boolean option.

Parameters:
shortForm - The option's short form
longForm - The option's long form
Returns:
The added option

addBooleanOption

public CLIOption addBooleanOption(String longForm)
Convenience method for adding a boolean option.

Parameters:
longForm - The option's long form
Returns:
The added option

getOptionValue

public Object getOptionValue(CLIOption o)
Gets given option's value.

Parameters:
o - The option whose value shall be returned
Returns:
The option's value or null if not present

getOptionValue

public Object getOptionValue(CLIOption o,
                             Object def,
                             boolean remove)
Gets given option's value.

Parameters:
o - The option whose value shall be returned
def - The default value to return if option is not present
remove - true to remove option's value from parser's known values; otherwise false
Returns:
The option's value or def if not present

getOptionValues

public final Collection<Object> getOptionValues(CLIOption option)
Gets the parsed values of all occurrences of given option, or an empty collection if the option was not set.

Parameters:
option - The option
Returns:
The parsed values of all occurrences of given option

getRemainingArgs

public String[] getRemainingArgs()
Returns:
the non-option arguments

parse

public void parse(String[] argv)
           throws CLIParseException,
                  CLIIllegalOptionValueException,
                  CLIUnknownOptionException
Parses specified command line.

Parameters:
argv - The command line arguments
Throws:
CLIParseException - If parsing fails
CLIIllegalOptionValueException - If an illegal option occurs
CLIUnknownOptionException - If an unknown option occurs

parse

public void parse(String[] argv,
                  Locale locale)
           throws CLIParseException,
                  CLIIllegalOptionValueException,
                  CLIUnknownOptionException
Parses specified command line.

Parameters:
argv - The command line arguments
locale - The locale
Throws:
CLIParseException - If parsing fails
CLIIllegalOptionValueException - If an illegal option occurs
CLIUnknownOptionException - If an unknown option occurs