1 package eu.svjatoslav.commons.commandline.parameterparser.parameter;
5 import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
6 import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
8 public class DirectoryParameter extends Parameter {
10 private ExistanceType existanceType = ExistanceType.DOES_NOT_MATTER;
12 public DirectoryParameter(final String description) {
13 super(description, ArgumentCount.SINGLE);
17 public DirectoryParameter addAliases(final String... aliasArray) {
18 super.addAliases(aliasArray);
23 public java.lang.String describeFormat() {
24 return existanceType.description + "directory";
27 public File getValue() {
29 if (arguments.size() != 1)
30 throw new RuntimeException("Parameter " + description
31 + " shall have exactly 1 argument.");
33 return new File(arguments.get(0));
36 public DirectoryParameter mustExist() {
37 existanceType = ExistanceType.MUST_EXIST;
41 public DirectoryParameter mustNotExist() {
42 existanceType = ExistanceType.MUST_NOT_EXIST;
47 public DirectoryParameter setMandatory() {
53 public boolean validate(final java.lang.String value) {
54 final File file = new File(value);
56 if (existanceType == ExistanceType.MUST_EXIST) {
57 if (file.exists() && file.isDirectory())
62 if (existanceType == ExistanceType.MUST_NOT_EXIST) {
68 if (existanceType == ExistanceType.DOES_NOT_MATTER) {