Class FileOption
java.lang.Object
eu.svjatoslav.commons.cli_helper.parameter_parser.Option<File,FileOption>
eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.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).-
Field Summary
Fields inherited from class eu.svjatoslav.commons.cli_helper.parameter_parser.Option
description, mandatory, parameters
-
Constructor Summary
ConstructorsConstructorDescriptionFileOption
(String description) Creates a FileOption requiring exactly one parameter that represents a file. -
Method Summary
Modifier and TypeMethodDescriptionProvides a short description of the expected format (e.g., "Existing file", "Non-existing file", or "File").getValue()
Returns the file chosen by the user (as aFile
object).protected static boolean
isFileValid
(ExistenceType existenceType, String path) Checks whether the given file path is valid according to the specifiedExistenceType
.boolean
Validates the given parameter against theExistenceType
rule.Enforces that the file path must point to an existing file.Enforces that the file path must not exist.Methods inherited from class eu.svjatoslav.commons.cli_helper.parameter_parser.Option
addAliases, addParameter, getAliasesAsString, getHelp, isMandatory, isPresent, matchesAlias, noMoreArguments, setMandatory, setPresent
-
Constructor Details
-
FileOption
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
Checks whether the given file path is valid according to the specifiedExistenceType
.- Parameters:
existenceType
- the required existence status for the filepath
- 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
Provides a short description of the expected format (e.g., "Existing file", "Non-existing file", or "File").- Specified by:
describeFormat
in classOption<File,
FileOption> - Returns:
- a string describing the format of this file parameter.
-
getValue
Returns the file chosen by the user (as aFile
object).- Specified by:
getValue
in classOption<File,
FileOption> - Returns:
- a
File
object constructed from the single parameter. - Throws:
RuntimeException
- if the option does not have exactly 1 parameter.
-
mustExist
Enforces that the file path must point to an existing file.- Returns:
- this FileOption instance, for method chaining
-
mustNotExist
Enforces that the file path must not exist.- Returns:
- this FileOption instance, for method chaining
-
isValid
Validates the given parameter against theExistenceType
rule.- Specified by:
isValid
in classOption<File,
FileOption> - Parameters:
value
- the file path to validate- Returns:
true
if the file path meets the existence requirement
-