de.esprit.common.clp

## Class CommandLineOption<T>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.common.clp.CommandLineOption<T>

- All Implemented Interfaces:
    Dumpable
  Direct Known Subclasses:
    AbstractBooleanOption, AbstractClassOption, AbstractDimensionOption, AbstractDoubleOption, AbstractIntegerOption, AbstractLocationOption, AbstractPathOption, AbstractStringOption, AbstractUrlOption, OptionCountry, OptionDBObject, OptionDBRecord, OptionLanguage, OptionLocale, OptionServer

      public abstract class CommandLineOption<T>
      extends DumpableObject

  This is the base class for all command line options.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CommandLineOption(java.lang.String option, java.lang.String helpText)`
    `CommandLineOption(java.lang.String option, java.lang.String argName, java.lang.String helpText)`
    `CommandLineOption(java.lang.String option, java.lang.String argName, java.lang.String helpText, boolean isMandatory)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkValue()` Performs additional checks on the entered option value (i.e. file existence etc..)
    `boolean` | `equals(java.lang.Object obj)` Compares the option by the 'option' field.
    `java.lang.String` | `getArgumentName()` Returns the name of the argument of this option (if any)
    `java.lang.String` | `getDefaultValue()`
    `java.lang.String` | `getEnvVariableName()` Returns the name of the env-variable that contains the default value - if one is defined
    `java.lang.String` | `getEnvVariableValue()` Returns the value of the ENV-variable if one is defined.
    `java.lang.String` | `getHelpText()`
    `java.lang.String` | `getOption()` Returns the option string (always starts with '-' or '+')
    `java.lang.String` | `getOptionAndArgument()`
    `java.lang.String` | `getStringValue()` Returns the string value of this option as read from the commandline
    `abstract T` | `getValue()` Returns the parsed value of this option.
    `boolean` | `hasArgument()` Tells whether this option expects an argument
    `int` | `hashCode()`
    `boolean` | `isMandatory()`
    `boolean` | `isPrintHelp()`
    `boolean` | `isPrintSyntax()`
    `boolean` | `isSecret()`
    `protected boolean` | `isValueTakenFromEnvVariable()`
    `void` | `parseDefaultValue()` If the option value is null but a defaultValue is defined then the latter is applied.
    `void` | `parseValue()` Parses the value from the command-line and applies it to this option.
    `protected abstract void` | `parseValue(java.lang.String value)` Parses and stores the given value from the command-line to this option.
    `void` | `setDefaultValue(java.lang.String defaultValue)` Set a default string value for this option.
    `void` | `setEnvVariableName(java.lang.String envVarName)` Defines the name of the ENV-variable which is looked up to find out a default value.
    `void` | `setFound(boolean wasFound)`
    `void` | `setHelpText(java.lang.String helpText)` Sets the help text for this option
    `void` | `setMandatory(boolean isMandatory)` Defines this option to be required.
    `void` | `setPrintHelp(boolean isPrintHelp)` Defines whether a help text is to be printed for this option (true by default).
    `void` | `setPrintSyntax(boolean isPrintSyntax)` Defines whether this option is to be printed in the syntax line (false by default).
    `void` | `setSecret(boolean isSecret)` Defines whether this is a secret option which is never printed neither in help text nor in syntax line.
    `void` | `setStringValue(java.lang.String value)`
    `DumpString` | `toDumpString(DumpString s)` This method allows subclasses to add values to the existing DumpString of the superclass.
    `ToString` | `toString(ToString s)` This method allows subclasses to add values to the existing ToString of the superclass.
    `boolean` | `wasFound()` Tells whether this option was found in the command-line.

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CommandLineOption

          public CommandLineOption(java.lang.String option,
                           java.lang.String helpText)

    - #### CommandLineOption

          public CommandLineOption(java.lang.String option,
                           java.lang.String argName,
                           java.lang.String helpText)

    - #### CommandLineOption

          public CommandLineOption(java.lang.String option,
                           java.lang.String argName,
                           java.lang.String helpText,
                           boolean isMandatory)

  - ### Method Detail

    - #### setEnvVariableName

          public final void setEnvVariableName(java.lang.String envVarName)

      Defines the name of the ENV-variable which is looked up to find out a default value. If no value for this option is given, then the value of the ENV-variable is used, if one is defined.

    - #### getEnvVariableName

          public final java.lang.String getEnvVariableName()

      Returns the name of the env-variable that contains the default value - if one is defined

    - #### getEnvVariableValue

          public final java.lang.String getEnvVariableValue()

      Returns the value of the ENV-variable if one is defined.

    - #### equals

          public boolean equals(java.lang.Object obj)

      Compares the option by the 'option' field.
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### wasFound

          public boolean wasFound()

      Tells whether this option was found in the command-line.

    - #### setFound

          public void setFound(boolean wasFound)

    - #### setSecret

          public void setSecret(boolean isSecret)

      Defines whether this is a secret option which is never printed neither in help text nor in syntax line.

    - #### isSecret

          public boolean isSecret()

    - #### setPrintHelp

          public void setPrintHelp(boolean isPrintHelp)

      Defines whether a help text is to be printed for this option (true by default).

    - #### isPrintHelp

          public boolean isPrintHelp()

    - #### setPrintSyntax

          public void setPrintSyntax(boolean isPrintSyntax)

      Defines whether this option is to be printed in the syntax line (false by default). Note: a mandatory option is always printed in the syntax line.

    - #### isPrintSyntax

          public boolean isPrintSyntax()

    - #### setMandatory

          public void setMandatory(boolean isMandatory)

      Defines this option to be required. It is an error if a mandatory option is not found in the command-line.

    - #### isMandatory

          public boolean isMandatory()

    - #### getOption

          public final java.lang.String getOption()

      Returns the option string (always starts with '-' or '+')

    - #### setHelpText

          public void setHelpText(java.lang.String helpText)

      Sets the help text for this option

    - #### getHelpText

          public final java.lang.String getHelpText()

    - #### getStringValue

          public final java.lang.String getStringValue()

      Returns the string value of this option as read from the commandline

    - #### setStringValue

          public final void setStringValue(java.lang.String value)

    - #### setDefaultValue

          public void setDefaultValue(java.lang.String defaultValue)

      Set a default string value for this option. If this option was not found in the command line then the the given default value is parsed (using `parseDefaultValue()`) and used.

    - #### getDefaultValue

          public java.lang.String getDefaultValue()

    - #### getValue

          public abstract T getValue()

      Returns the parsed value of this option.

    - #### parseValue

          public final void parseValue()
                                throws java.lang.Exception

      Parses the value from the command-line and applies it to this option. Calls `parseValue(String)` with the value read from the command line
      Throws:
        `java.lang.Exception`

    - #### parseDefaultValue

          public final void parseDefaultValue()
                                       throws java.lang.Exception

      If the option value is null but a defaultValue is defined then the latter is applied.
      Throws:
        `java.lang.Exception`

    - #### isValueTakenFromEnvVariable

          protected final boolean isValueTakenFromEnvVariable()

    - #### checkValue

          public void checkValue()
                          throws java.lang.Exception

      Performs additional checks on the entered option value (i.e. file existence etc..) If the option value is null but a defaultValue is defined then the latter is applied. The option may also check its dependencies of other options.
      Throws:
        `java.lang.Exception`

    - #### parseValue

          protected abstract void parseValue(java.lang.String value)
                                      throws java.lang.Exception

      Parses and stores the given value from the command-line to this option. Subclasses perform any type conversion if necessary.
      Throws:
        `java.lang.Exception`

    - #### hasArgument

          public final boolean hasArgument()

      Tells whether this option expects an argument

    - #### getArgumentName

          public final java.lang.String getArgumentName()

      Returns the name of the argument of this option (if any)

    - #### getOptionAndArgument

          public final java.lang.String getOptionAndArgument()

    - #### toString

          public ToString toString(ToString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing ToString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toString` in interface `Dumpable`
      Overrides:
        `toString` in class `DumpableObject`

    - #### toDumpString

          public DumpString toDumpString(DumpString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing DumpString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toDumpString` in interface `Dumpable`
      Overrides:
        `toDumpString` in class `DumpableObject`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.