com.x1seven.hydrogen.cli
Class CommandLineInterpreter

java.lang.Object
  extended by com.x1seven.hydrogen.cli.CommandLineInterpreter

public class CommandLineInterpreter
extends java.lang.Object

Service object for interpreting command-line arguments.

Since:
1.0.0
Version:
1.2
Author:
brendonm

Constructor Summary
CommandLineInterpreter()
           
 
Method Summary
 boolean getBooleanArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, java.lang.String[] args, boolean defaultValue)
          Retrieves the value for the argument with switch matching either the short or the long argument name, or returns the supplied default value if no matching argument was found.
 int getIntArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, java.lang.String[] args)
           
 java.lang.String[] getPlainValues(java.lang.String[] args)
          Builds an array which is contains all of the values from the supplied arguments array that are not switches (don't start with - or --).
 java.lang.String getStringArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, boolean required, java.lang.String[] args)
           
 java.lang.String getStringArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, boolean required, java.lang.String defaultValue, java.lang.String[] args)
          Retrieves the value for the argument with switch matching either the short or the long argument name, or returns the supplied default value if no matching argument was found.
 java.lang.String getStringArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, java.lang.String[] args)
          Retrieves the value for the argument with switch matching either the short or the long argument name.
 java.lang.String getStringArgumentValue(java.lang.String shortArgumentName, java.lang.String longArgumentName, java.lang.String defaultValue, java.lang.String[] args)
           
 boolean hasNoValueArgument(java.lang.String shortArgumentName, java.lang.String longArgumentName, java.lang.String[] args)
          Checks if the supplied arguments contain the named switch without a value.
 void validateArgumentSwitches(java.lang.String[] args)
          Syntactic validation of the switches.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineInterpreter

public CommandLineInterpreter()
Method Detail

validateArgumentSwitches

public void validateArgumentSwitches(java.lang.String[] args)
                              throws CommandLineInterpreterException
Syntactic validation of the switches.

Throws:
CommandLineInterpreterException

getStringArgumentValue

public java.lang.String getStringArgumentValue(java.lang.String shortArgumentName,
                                               java.lang.String longArgumentName,
                                               java.lang.String[] args)
                                        throws CommandLineInterpreterException
Retrieves the value for the argument with switch matching either the short or the long argument name. If more than one matching argument is found then an exception is thrown. If an argument is found with no value, then an exception is thrown. If no matching argument is found the method returns null.

Throws:
CommandLineInterpreterException

getStringArgumentValue

public java.lang.String getStringArgumentValue(java.lang.String shortArgumentName,
                                               java.lang.String longArgumentName,
                                               boolean required,
                                               java.lang.String[] args)
                                        throws CommandLineInterpreterException
Throws:
CommandLineInterpreterException

getStringArgumentValue

public java.lang.String getStringArgumentValue(java.lang.String shortArgumentName,
                                               java.lang.String longArgumentName,
                                               java.lang.String defaultValue,
                                               java.lang.String[] args)
                                        throws CommandLineInterpreterException
Throws:
CommandLineInterpreterException

getStringArgumentValue

public java.lang.String getStringArgumentValue(java.lang.String shortArgumentName,
                                               java.lang.String longArgumentName,
                                               boolean required,
                                               java.lang.String defaultValue,
                                               java.lang.String[] args)
                                        throws CommandLineInterpreterException
Retrieves the value for the argument with switch matching either the short or the long argument name, or returns the supplied default value if no matching argument was found. If more than one matching argument is found then an exception is thrown. If an argument is found with no value, then an exception is thrown.

Throws:
CommandLineInterpreterException

getIntArgumentValue

public int getIntArgumentValue(java.lang.String shortArgumentName,
                               java.lang.String longArgumentName,
                               java.lang.String[] args)
                        throws CommandLineInterpreterException
Throws:
CommandLineInterpreterException

hasNoValueArgument

public boolean hasNoValueArgument(java.lang.String shortArgumentName,
                                  java.lang.String longArgumentName,
                                  java.lang.String[] args)
                           throws CommandLineInterpreterException
Checks if the supplied arguments contain the named switch without a value.

Throws:
CommandLineInterpreterException

getBooleanArgumentValue

public boolean getBooleanArgumentValue(java.lang.String shortArgumentName,
                                       java.lang.String longArgumentName,
                                       java.lang.String[] args,
                                       boolean defaultValue)
                                throws CommandLineInterpreterException
Retrieves the value for the argument with switch matching either the short or the long argument name, or returns the supplied default value if no matching argument was found. If more than one matching argument is found then an exception is thrown. If an argument is found with no value, then an exception is thrown.

Throws:
CommandLineInterpreterException

getPlainValues

public java.lang.String[] getPlainValues(java.lang.String[] args)
Builds an array which is contains all of the values from the supplied arguments array that are not switches (don't start with - or --).