X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fcli_helper%2Fparameter_parser%2FOption.java;h=d5916638c8c80b7d8053bc238f6f189299419568;hb=b4b3152b0012f4e0b0b5d3e98cc8a7e4a12e8c18;hp=cb36966ae9437e05cf530bbbe838dd0a0400f419;hpb=324ea20c0c65f671c0d35e94ed90142912a56b4c;p=cli-helper.git diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Option.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Option.java index cb36966..d591663 100755 --- a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Option.java +++ b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Option.java @@ -12,6 +12,14 @@ import static java.lang.String.join; import static java.util.Collections.addAll; import static java.util.stream.Collectors.joining; +/** + * Represents an option that can be provided on CLI. + * This class allows specifying whether the option is mandatory, + * the parameter count, a description, and any aliases for the option. + * + * @param type of value that this option returns. + * @param type of this option. + */ public abstract class Option { /** @@ -43,6 +51,16 @@ public abstract class Option { */ private boolean isPresent; + /** + * Represents an option that can be provided on CLI. + * This class allows specifying whether the option is mandatory, + * the parameter count, a description, and any aliases for the option. + * + * @param mandatory indicates whether the option is mandatory + * @param parameterCount the number of parameters required for the option + * @param description a description of the option + * @param aliases2 any additional aliases for the option + */ public Option(final boolean mandatory, final ParameterCount parameterCount, final String description, final String... aliases2) { @@ -60,6 +78,12 @@ public abstract class Option { this.parameterCount = parameterCount; } + /** + * Adds additional aliases to the option. + * + * @param aliasArray an array of strings representing the aliases to be added + * @return the modified option object + */ @SuppressWarnings("unchecked") public I addAliases(final String... aliasArray) { @@ -85,7 +109,7 @@ public abstract class Option { // 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()); @@ -117,7 +141,9 @@ public abstract class Option { } /** - * @return help for this option. + * Returns the help message for this parameter. + * + * @return the help message as a string. */ public String getHelp() { final StringBuilder result = new StringBuilder(); @@ -131,7 +157,7 @@ public abstract class Option { .append(describeFormat()) .append(")"); - if (parameterCount.equals(ParameterCount.MULTI)) + if (parameterCount.equals(ParameterCount.ONE_OR_MORE)) result.append("..."); } result.append("\n"); @@ -142,6 +168,11 @@ public abstract class Option { return result.toString(); } + /** + * Returns the value of the object. + * + * @return the value of the object. + */ public abstract T getValue(); public boolean isMandatory() { @@ -149,14 +180,17 @@ public abstract class Option { } /** - * @return the parameterSpecified + * @return true if this parameter was present in the commandline. */ public boolean isPresent() { return isPresent; } /** - * @param present the parameterSpecified to set + * Sets the present status of this parameter. + * + * @param present true if this parameter is present in the command line, + * false otherwise. */ protected void setPresent(final boolean present) { this.isPresent = present; @@ -192,6 +226,12 @@ public abstract class Option { return true; } + /** + * Sets the option as mandatory. This means that the option must be provided by the user + * in order for the program to run successfully. + * + * @return The updated instance of the option. + */ @SuppressWarnings("unchecked") public I setMandatory() { mandatory = true;