X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fcli_helper%2Fparameter_parser%2Fparameter%2FFileOption.java;h=c10ec1e63d7e58fe7ee6e00e04a09591df0cf826;hb=HEAD;hp=db941c4d1744a8de5256c03020fab869db675b2f;hpb=324ea20c0c65f671c0d35e94ed90142912a56b4c;p=cli-helper.git diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileOption.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileOption.java index db941c4..c10ec1e 100755 --- a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileOption.java +++ b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileOption.java @@ -9,12 +9,16 @@ import eu.svjatoslav.commons.cli_helper.parameter_parser.Option; import java.io.File; +/** + * This class represents commandline option which accepts exactly one parameter + * which is a file. + */ public class FileOption extends Option { private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER; public FileOption(final String description) { - super(description, ParameterCount.SINGLE); + super(description, ParameterCount.ONE); } protected static boolean validateFile(ExistenceType existenceType, String value) { @@ -41,7 +45,14 @@ public class FileOption extends Option { @Override public java.lang.String describeFormat() { - return existenceType.description + " file"; + switch (existenceType) { + case MUST_EXIST: + return "Existing file."; + case MUST_NOT_EXIST: + return "Non-existing file."; + default: + return "File."; + } } @Override @@ -54,11 +65,21 @@ public class FileOption extends Option { return new File(parameters.get(0)); } + /** + * This method sets that file shall exist. + * + * @return This object. + */ public FileOption mustExist() { existenceType = ExistenceType.MUST_EXIST; return this; } + /** + * This method sets that file shall not exist. + * + * @return This object. + */ public FileOption mustNotExist() { existenceType = ExistenceType.MUST_NOT_EXIST; return this;