This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit f2aa3089560eb00cc973b0cb12ead7c3424536bb Author: Gary Gregory <[email protected]> AuthorDate: Wed Oct 6 08:24:18 2021 -0400 Rename some internals. --- src/main/java/org/apache/commons/cli/Option.java | 27 ++++++++++------------ .../org/apache/commons/cli/OptionValidator.java | 23 +++++++++--------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java index 7b8f2d6..4742ff2 100644 --- a/src/main/java/org/apache/commons/cli/Option.java +++ b/src/main/java/org/apache/commons/cli/Option.java @@ -83,8 +83,7 @@ public class Option implements Cloneable, Serializable { * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt} */ private Builder(final String option) throws IllegalArgumentException { - OptionValidator.validateOption(option); - this.option = option; + this.option = OptionValidator.validate(option); } /** @@ -332,44 +331,42 @@ public class Option implements Cloneable, Serializable { /** * Creates an Option using the specified parameters. * - * @param opt short representation of the option + * @param option short representation of the option * @param hasArg specifies whether the Option takes an argument or not * @param description describes the function of the option * * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}. */ - public Option(final String opt, final boolean hasArg, final String description) throws IllegalArgumentException { - this(opt, null, hasArg, description); + public Option(final String option, final boolean hasArg, final String description) throws IllegalArgumentException { + this(option, null, hasArg, description); } /** * Creates an Option using the specified parameters. The option does not take an argument. * - * @param opt short representation of the option + * @param option short representation of the option * @param description describes the function of the option * * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}. */ - public Option(final String opt, final String description) throws IllegalArgumentException { - this(opt, null, false, description); + public Option(final String option, final String description) throws IllegalArgumentException { + this(option, null, false, description); } /** * Creates an Option using the specified parameters. * - * @param opt short representation of the option - * @param longOpt the long representation of the option + * @param option short representation of the option + * @param longOption the long representation of the option * @param hasArg specifies whether the Option takes an argument or not * @param description describes the function of the option * * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}. */ - public Option(final String opt, final String longOpt, final boolean hasArg, final String description) throws IllegalArgumentException { + public Option(final String option, final String longOption, final boolean hasArg, final String description) throws IllegalArgumentException { // ensure that the option is valid - OptionValidator.validateOption(opt); - - this.opt = opt; - this.longOpt = longOpt; + this.opt = OptionValidator.validate(option); + this.longOpt = longOption; // if hasArg is set then the number of arguments is 1 if (hasArg) { diff --git a/src/main/java/org/apache/commons/cli/OptionValidator.java b/src/main/java/org/apache/commons/cli/OptionValidator.java index 4fea227..2cf2dda 100644 --- a/src/main/java/org/apache/commons/cli/OptionValidator.java +++ b/src/main/java/org/apache/commons/cli/OptionValidator.java @@ -54,31 +54,30 @@ final class OptionValidator { * <p> * In case {@code opt} is {@code null} no further validation is performed. * - * @param opt The option string to validate, may be null + * @param option The option string to validate, may be null * @throws IllegalArgumentException if the Option is not valid. */ - static void validateOption(final String opt) throws IllegalArgumentException { + static String validate(final String option) throws IllegalArgumentException { // if opt is NULL do not check further - if (opt == null) { - return; + if (option == null) { + return option; } // handle the single character opt - if (opt.length() == 1) { - final char ch = opt.charAt(0); + if (option.length() == 1) { + final char ch = option.charAt(0); if (!isValidOpt(ch)) { throw new IllegalArgumentException("Illegal option name '" + ch + "'"); } - } - - // handle the multi character opt - else { - for (final char ch : opt.toCharArray()) { + } else { + // handle the multi character opt + for (final char ch : option.toCharArray()) { if (!isValidChar(ch)) { - throw new IllegalArgumentException("The option '" + opt + "' contains an illegal " + "character : '" + ch + "'"); + throw new IllegalArgumentException("The option '" + option + "' contains an illegal " + "character : '" + ch + "'"); } } } + return option; } }
