Class Option<T,I extends Option>

java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<T,I>
Type Parameters:
T - type of value that this option returns.
I - type of this option.
Direct Known Subclasses:
DirectoryOption, DirectoryOptions, FileOption, FileOptions, FloatOption, IntegerOption, NullOption, StringOption, StringOptions

public abstract class Option<T,I extends Option> extends Object
Represents an option that can be provided on CLI. This class allows specifying whether the option is mandatory, the parameter count, a description, and any aliases for the option.
  • Field Details

    • description

      public final String description
      Purpose of this option, like: input image path, compression level, etc... Note: for describing option type there is describeFormat().
    • parameters

      public final List<String> parameters
      List of arguments for this parameter.
    • mandatory

      protected boolean mandatory
      Indicates that at least one parameter is mandatory for this option.
  • Constructor Details

    • Option

      public Option(boolean mandatory, ParameterCount parameterCount, String description, String... aliases2)
      Represents an option that can be provided on CLI. This class allows specifying whether the option is mandatory, the parameter count, a description, and any aliases for the option.
      Parameters:
      mandatory - indicates whether the option is mandatory
      parameterCount - the number of parameters required for the option
      description - a description of the option
      aliases2 - any additional aliases for the option
    • Option

      public Option(String description, ParameterCount parameterCount)
  • Method Details

    • addAliases

      public I addAliases(String... aliasArray)
      Adds additional aliases to the option.
      Parameters:
      aliasArray - an array of strings representing the aliases to be added
      Returns:
      the modified option object
    • addParameter

      public boolean addParameter(String parameterString)
      Parameters:
      parameterString - parameter to add
      Returns:
      true if no errors were found. false otherwise.
    • describeFormat

      public abstract String describeFormat()
      Returns:
      Single line parameter type description. For example: "file", "date", "integer", "regular expression", etc..

      Note: for argument purpose description there is description

    • getAliasesAsString

      public String getAliasesAsString()
      Returns:
      aliases for this parameter as string.
    • getHelp

      public String getHelp()
      Returns the help message for this parameter.
      Returns:
      the help message as a string.
    • getValue

      public abstract T getValue()
      Returns the value of the object.
      Returns:
      the value of the object.
    • isMandatory

      public boolean isMandatory()
    • isPresent

      public boolean isPresent()
      Returns:
      true if this parameter was present in the commandline.
    • setPresent

      protected void setPresent(boolean present)
      Sets the present status of this parameter.
      Parameters:
      present - true if this parameter is present in the command line, false otherwise.
    • matchesAlias

      public boolean matchesAlias(String alias)
      Parameters:
      alias - alias to check against
      Returns:
      true if given alias is registered for this parameter.
    • noMoreArguments

      public boolean noMoreArguments()
      Notifies this option that no more parameters will follow. This gives option chance to verify if this is ok.
      Returns:
      true if no errors were found. false otherwise.
    • setMandatory

      public I setMandatory()
      Sets the option as mandatory. This means that the option must be provided by the user in order for the program to run successfully.
      Returns:
      The updated instance of the option.
    • isValid

      public abstract boolean isValid(String value)
      Parameters:
      value - value to validate
      Returns:
      true if value is correct, false otherwise.