Skip to content

Commit f2aa308

Browse files
committed
Rename some internals.
1 parent caf0b99 commit f2aa308

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/main/java/org/apache/commons/cli/Option.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public static final class Builder {
8383
* @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}
8484
*/
8585
private Builder(final String option) throws IllegalArgumentException {
86-
OptionValidator.validateOption(option);
87-
this.option = option;
86+
this.option = OptionValidator.validate(option);
8887
}
8988

9089
/**
@@ -332,44 +331,42 @@ private Option(final Builder builder) {
332331
/**
333332
* Creates an Option using the specified parameters.
334333
*
335-
* @param opt short representation of the option
334+
* @param option short representation of the option
336335
* @param hasArg specifies whether the Option takes an argument or not
337336
* @param description describes the function of the option
338337
*
339338
* @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}.
340339
*/
341-
public Option(final String opt, final boolean hasArg, final String description) throws IllegalArgumentException {
342-
this(opt, null, hasArg, description);
340+
public Option(final String option, final boolean hasArg, final String description) throws IllegalArgumentException {
341+
this(option, null, hasArg, description);
343342
}
344343

345344
/**
346345
* Creates an Option using the specified parameters. The option does not take an argument.
347346
*
348-
* @param opt short representation of the option
347+
* @param option short representation of the option
349348
* @param description describes the function of the option
350349
*
351350
* @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}.
352351
*/
353-
public Option(final String opt, final String description) throws IllegalArgumentException {
354-
this(opt, null, false, description);
352+
public Option(final String option, final String description) throws IllegalArgumentException {
353+
this(option, null, false, description);
355354
}
356355

357356
/**
358357
* Creates an Option using the specified parameters.
359358
*
360-
* @param opt short representation of the option
361-
* @param longOpt the long representation of the option
359+
* @param option short representation of the option
360+
* @param longOption the long representation of the option
362361
* @param hasArg specifies whether the Option takes an argument or not
363362
* @param description describes the function of the option
364363
*
365364
* @throws IllegalArgumentException if there are any non valid Option characters in {@code opt}.
366365
*/
367-
public Option(final String opt, final String longOpt, final boolean hasArg, final String description) throws IllegalArgumentException {
366+
public Option(final String option, final String longOption, final boolean hasArg, final String description) throws IllegalArgumentException {
368367
// ensure that the option is valid
369-
OptionValidator.validateOption(opt);
370-
371-
this.opt = opt;
372-
this.longOpt = longOpt;
368+
this.opt = OptionValidator.validate(option);
369+
this.longOpt = longOption;
373370

374371
// if hasArg is set then the number of arguments is 1
375372
if (hasArg) {

src/main/java/org/apache/commons/cli/OptionValidator.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,30 @@ private static boolean isValidOpt(final char c) {
5454
* <p>
5555
* In case {@code opt} is {@code null} no further validation is performed.
5656
*
57-
* @param opt The option string to validate, may be null
57+
* @param option The option string to validate, may be null
5858
* @throws IllegalArgumentException if the Option is not valid.
5959
*/
60-
static void validateOption(final String opt) throws IllegalArgumentException {
60+
static String validate(final String option) throws IllegalArgumentException {
6161
// if opt is NULL do not check further
62-
if (opt == null) {
63-
return;
62+
if (option == null) {
63+
return option;
6464
}
6565

6666
// handle the single character opt
67-
if (opt.length() == 1) {
68-
final char ch = opt.charAt(0);
67+
if (option.length() == 1) {
68+
final char ch = option.charAt(0);
6969

7070
if (!isValidOpt(ch)) {
7171
throw new IllegalArgumentException("Illegal option name '" + ch + "'");
7272
}
73-
}
74-
75-
// handle the multi character opt
76-
else {
77-
for (final char ch : opt.toCharArray()) {
73+
} else {
74+
// handle the multi character opt
75+
for (final char ch : option.toCharArray()) {
7876
if (!isValidChar(ch)) {
79-
throw new IllegalArgumentException("The option '" + opt + "' contains an illegal " + "character : '" + ch + "'");
77+
throw new IllegalArgumentException("The option '" + option + "' contains an illegal " + "character : '" + ch + "'");
8078
}
8179
}
8280
}
81+
return option;
8382
}
8483
}

0 commit comments

Comments
 (0)