Refactored the ParameterCount enum for clearer representation - 'SINGLE' and 'MULTI' changed to 'ONE' and 'ONE_OR_MORE'. Also updated various option descriptions for better readability and consistency. The describeFormat() methods in different file/directory options now contain clear messages about the existence of the resource, improving user experience.
// check if multiple arguments are allowed
if ((!parameters.isEmpty())
- && (parameterCount.equals(ParameterCount.SINGLE))) {
+ && (parameterCount.equals(ParameterCount.ONE))) {
System.out
.println("Error! Only single parameter is allowed for argument(s): "
+ getAliasesAsString());
.append(describeFormat())
.append(")");
- if (parameterCount.equals(ParameterCount.MULTI))
+ if (parameterCount.equals(ParameterCount.ONE_OR_MORE))
result.append("...");
}
result.append("\n");
package eu.svjatoslav.commons.cli_helper.parameter_parser;
/**
- * This enum is used to define how many parameters con be given to particular option.
+ * This enumeration is used to define how many parameters
+ * does particular commandline option accept.
*/
public enum ParameterCount {
* Option has no parameters.
*/
NONE,
+
/**
- * Option has exactly one parameter.
+ * Option has exactly one mandatory parameter.
*/
- SINGLE,
+ ONE,
/**
- * Option can have any amount of parameters.
+ * Option must have one or more parameters.
*/
- MULTI
+ ONE_OR_MORE
}
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
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.";
+ }
}
@Override
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
public DirectoryOptions(final String description) {
- super(description, ParameterCount.MULTI);
+ super(description, ParameterCount.ONE_OR_MORE);
}
@Override
public String describeFormat() {
- return existenceType.description + " directories";
+ switch (existenceType) {
+ case MUST_EXIST:
+ return "One to many existing directories.";
+ case MUST_NOT_EXIST:
+ return "One to many non-existing directories.";
+ default:
+ return "One to many directories.";
+ }
}
@Override
/**
* Resource shall exist.
*/
- MUST_EXIST("existing"),
+ MUST_EXIST,
/**
* Resource shall not exist.
*/
- MUST_NOT_EXIST("not existing"),
+ MUST_NOT_EXIST,
/**
* Resource existence does not matter.
*/
- DOES_NOT_MATTER("");
-
- /**
- * Human readable description of existence type.
- */
- public final String description;
-
- ExistenceType(final String description) {
- this.description = description;
- }
+ DOES_NOT_MATTER;
}
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) {
@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
*/
package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
-import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
import java.io.File;
import java.util.List;
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
public FileOptions(final String description) {
- super(description, ParameterCount.MULTI);
+ super(description, ParameterCount.ONE_OR_MORE);
}
@Override
public String describeFormat() {
- return existenceType.description + " files";
+ switch (existenceType) {
+ case MUST_EXIST:
+ return "One to many existing files.";
+ case MUST_NOT_EXIST:
+ return "One to many non-existing files.";
+ default:
+ return "One to many files.";
+ }
}
@Override
public class IntegerOption extends Option<Integer, IntegerOption> {
public IntegerOption(final String description) {
- super(description, ParameterCount.SINGLE);
+ super(description, ParameterCount.ONE);
}
@Override
public java.lang.String describeFormat() {
- return "integer";
+ return "Integer.";
}
@Override
@Override
public java.lang.String describeFormat() {
- return "<none>";
+ return "None.";
}
@Override
public final String defaultValue;
public StringOption(final String description) {
- super(description, ParameterCount.SINGLE);
+ super(description, ParameterCount.ONE);
defaultValue = null;
}
public StringOption(final String description, String defaultValue) {
- super(description, ParameterCount.SINGLE);
+ super(description, ParameterCount.ONE);
this.defaultValue = defaultValue;
this.setPresent(true);
}
@Override
public java.lang.String describeFormat() {
- return "string";
+ return "String.";
}
@Override
public class StringOptions extends Option<List<String>, StringOptions> {
public StringOptions(final String description) {
- super(description, ParameterCount.MULTI);
+ super(description, ParameterCount.ONE_OR_MORE);
}
@Override
public java.lang.String describeFormat() {
- return "one to many strings";
+ return "One to many string.";
}
@Override