X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=cli-helper.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fcli_helper%2Fparameter_parser%2Fparameter%2FDirectoryOption.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fcli_helper%2Fparameter_parser%2Fparameter%2FDirectoryOption.java;h=ee52751bc2af296482c151d4de8a283171a8fbf2;hp=718aa0966a292d09d7cf0a5b849469828e37ab1c;hb=b4b3152b0012f4e0b0b5d3e98cc8a7e4a12e8c18;hpb=e8f029969d48634280dc5ad9d9c43ba4c0699cd9 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 718aa09..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,10 +9,22 @@ 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.ONE); } @@ -29,6 +41,12 @@ public class DirectoryOption extends Option { } } + /** + * 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() { @@ -39,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);