X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fcli_helper%2Fparameter_parser%2Fparameter%2FDirectoryOption.java;h=ee52751bc2af296482c151d4de8a283171a8fbf2;hb=b4b3152b0012f4e0b0b5d3e98cc8a7e4a12e8c18;hp=8f97a8b8d5c7b949b11bc4b1a678008cf1a7b319;hpb=324ea20c0c65f671c0d35e94ed90142912a56b4c;p=cli-helper.git diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryOption.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryOption.java index 8f97a8b..ee52751 100755 --- a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryOption.java +++ b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryOption.java @@ -9,19 +9,44 @@ import eu.svjatoslav.commons.cli_helper.parameter_parser.Option; import java.io.File; + +/** + * This class is used to define commandline option which accepts directory as parameter. + */ public class DirectoryOption extends Option { + /** + * This enum is used to define if directory shall exist in filesystem or not. + */ private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER; + /** + * Constructor. + * + * @param description Description of the option. + */ public DirectoryOption(final String description) { - super(description, ParameterCount.SINGLE); + super(description, ParameterCount.ONE); } @Override public java.lang.String describeFormat() { - return existenceType.description + " directory"; + switch (existenceType) { + case MUST_EXIST: + return "Existing directory."; + case MUST_NOT_EXIST: + return "Non-existing directory."; + default: + return "Directory."; + } } + /** + * Retrieves the value of the option as a {@link File} object. + * + * @return The value of the option as a {@link File} object. + * @throws RuntimeException if the option does not have exactly 1 argument. + */ @Override public File getValue() { @@ -32,16 +57,32 @@ public class DirectoryOption extends Option { return new File(parameters.get(0)); } + /** + * This method sets that directory shall exist. + * + * @return This object. + */ public DirectoryOption mustExist() { existenceType = ExistenceType.MUST_EXIST; return this; } + /** + * This method sets that directory shall not exist. + * + * @return This object. + */ public DirectoryOption mustNotExist() { existenceType = ExistenceType.MUST_NOT_EXIST; return this; } + /** + * This method checks if a provided directory path is valid based on the specified existence type. + * + * @param value The directory path to validate. + * @return True if the directory path is valid according to the existence type, otherwise false. + */ @Override public boolean isValid(final java.lang.String value) { final File file = new File(value);