java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<File,FileOption>
eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileOption

public class FileOption extends Option<File,FileOption>
Represents a command-line option that accepts exactly one parameter which is interpreted as a file path. By default, ExistenceType.DOES_NOT_MATTER is used (i.e., the file may or may not exist).
  • Constructor Details

    • FileOption

      public FileOption(String description)
      Creates a FileOption requiring exactly one parameter that represents a file.
      Parameters:
      description - a brief description of what this option is for (e.g., "Path to input file").
  • Method Details

    • isFileValid

      protected static boolean isFileValid(ExistenceType existenceType, String path)
      Checks whether the given file path is valid according to the specified ExistenceType.
      Parameters:
      existenceType - the required existence status for the file
      path - the file path to validate
      Returns:
      true if the path meets the existence requirement and is not a directory when it must be a file.
    • describeFormat

      public String describeFormat()
      Provides a short description of the expected format (e.g., "Existing file", "Non-existing file", or "File").
      Specified by:
      describeFormat in class Option<File,FileOption>
      Returns:
      a string describing the format of this file parameter.
    • getValue

      public File getValue()
      Returns the file chosen by the user (as a File object).
      Specified by:
      getValue in class Option<File,FileOption>
      Returns:
      a File object constructed from the single parameter.
      Throws:
      RuntimeException - if the option does not have exactly 1 parameter.
    • mustExist

      public FileOption mustExist()
      Enforces that the file path must point to an existing file.
      Returns:
      this FileOption instance, for method chaining
    • mustNotExist

      public FileOption mustNotExist()
      Enforces that the file path must not exist.
      Returns:
      this FileOption instance, for method chaining
    • isValid

      public boolean isValid(String value)
      Validates the given parameter against the ExistenceType rule.
      Specified by:
      isValid in class Option<File,FileOption>
      Parameters:
      value - the file path to validate
      Returns:
      true if the file path meets the existence requirement