java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<String,StringOption>
eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.StringOption

public class StringOption extends Option<String,StringOption>
Represents a command-line option that accepts exactly one string parameter. An optional default value can be provided; if so, this option is considered "present" even without user input.
  • Field Details

    • defaultValue

      public final String defaultValue
      Default value to return if the user does not provide a parameter. If non-null, this option is automatically considered present.
  • Constructor Details

    • StringOption

      public StringOption(String description)
      Constructs a StringOption with no default value.
      Parameters:
      description - a brief description of what this option does.
    • StringOption

      public StringOption(String description, String defaultValue)
      Constructs a StringOption with a specified default value.
      Parameters:
      description - a brief description of what this option does.
      defaultValue - the default string to use if the user does not supply a parameter.
  • Method Details

    • describeFormat

      public String describeFormat()
      Description copied from class: Option
      Describes the kind or format of the expected parameter(s), e.g. "File", "Integer", etc.
      Specified by:
      describeFormat in class Option<String,StringOption>
      Returns:
      a short string describing the parameter format
    • getValue

      public String getValue()
      Returns the string parameter or the default value if none was provided.
      Specified by:
      getValue in class Option<String,StringOption>
      Returns:
      the parsed value as the generic type T.
      Throws:
      RuntimeException - if multiple parameters were provided.
    • isValid

      public boolean isValid(String value)
      Always returns true since any string is considered valid for this option.
      Specified by:
      isValid in class Option<String,StringOption>
      Parameters:
      value - the parameter string to test
      Returns:
      true if valid; false otherwise