Skip to content

Commit b3cdbea

Browse files
committed
Use ternary
Whitespace
1 parent 58114d9 commit b3cdbea

1 file changed

Lines changed: 1 addition & 32 deletions

File tree

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ protected void checkRequiredOptions() throws MissingOptionException {
251251
*/
252252
private String getLongPrefix(final String token) {
253253
final String t = Util.stripLeadingHyphens(token);
254-
255254
int i;
256255
String opt = null;
257256
for (i = t.length() - 2; i > 1; i--) {
@@ -261,7 +260,6 @@ private String getLongPrefix(final String token) {
261260
break;
262261
}
263262
}
264-
265263
return opt;
266264
}
267265

@@ -280,7 +278,6 @@ private List<String> getMatchingLongOptions(final String token) {
280278
final Option option = options.getOption(token);
281279
matches.add(option.getLongOpt());
282280
}
283-
284281
return matches;
285282
}
286283

@@ -307,7 +304,6 @@ private List<String> getMatchingLongOptions(final String token) {
307304
protected void handleConcatenatedOptions(final String token) throws ParseException {
308305
for (int i = 1; i < token.length(); i++) {
309306
final String ch = String.valueOf(token.charAt(i));
310-
311307
if (!options.hasOption(ch)) {
312308
handleUnknownToken(stopAtNonOption && i > 1 ? token.substring(i) : token);
313309
break;
@@ -346,11 +342,8 @@ private void handleLongOption(final String token) throws ParseException {
346342
*/
347343
private void handleLongOptionWithEqual(final String token) throws ParseException {
348344
final int pos = token.indexOf('=');
349-
350345
final String value = token.substring(pos + 1);
351-
352346
final String opt = token.substring(0, pos);
353-
354347
final List<String> matchingOpts = getMatchingLongOptions(opt);
355348
if (matchingOpts.isEmpty()) {
356349
handleUnknownToken(currentToken);
@@ -359,7 +352,6 @@ private void handleLongOptionWithEqual(final String token) throws ParseException
359352
} else {
360353
final String key = options.hasLongOption(opt) ? opt : matchingOpts.get(0);
361354
final Option option = options.getOption(key);
362-
363355
if (option.acceptsArg()) {
364356
handleOption(option);
365357
currentOption.addValueForProcessing(stripLeadingAndTrailingQuotesDefaultOff(value));
@@ -392,18 +384,10 @@ private void handleLongOptionWithoutEqual(final String token) throws ParseExcept
392384
private void handleOption(final Option option) throws ParseException {
393385
// check the previous option before handling the next one
394386
checkRequiredArgs();
395-
396387
final Option copy = (Option) option.clone();
397-
398388
updateRequiredOptions(copy);
399-
400389
cmd.addOption(copy);
401-
402-
if (copy.hasArg()) {
403-
currentOption = copy;
404-
} else {
405-
currentOption = null;
406-
}
390+
currentOption = copy.hasArg() ? copy : null;
407391
}
408392

409393
/**
@@ -415,19 +399,15 @@ private void handleProperties(final Properties properties) throws ParseException
415399
if (properties == null) {
416400
return;
417401
}
418-
419402
for (final Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
420403
final String option = e.nextElement().toString();
421-
422404
final Option opt = options.getOption(option);
423405
if (opt == null) {
424406
throw new UnrecognizedOptionException("Default option wasn't defined", option);
425407
}
426-
427408
// if the option is part of a group, check if another option of the group has been selected
428409
final OptionGroup group = options.getOptionGroup(opt);
429410
final boolean selected = group != null && group.getSelected() != null;
430-
431411
if (!cmd.hasOption(option) && !selected) {
432412
// get the value from the properties
433413
final String value = properties.getProperty(option);
@@ -440,7 +420,6 @@ private void handleProperties(final Properties properties) throws ParseException
440420
// if the value is not yes, true or 1 then don't add the option to the CommandLine
441421
continue;
442422
}
443-
444423
handleOption(opt);
445424
currentOption = null;
446425
}
@@ -458,9 +437,7 @@ private void handleProperties(final Properties properties) throws ParseException
458437
*/
459438
private void handleShortAndLongOption(final String token) throws ParseException {
460439
final String t = Util.stripLeadingHyphens(token);
461-
462440
final int pos = t.indexOf('=');
463-
464441
if (t.length() == 1) {
465442
// -S
466443
if (options.hasShortOption(t)) {
@@ -529,7 +506,6 @@ private void handleShortAndLongOption(final String token) throws ParseException
529506
*/
530507
private void handleToken(final String token) throws ParseException {
531508
currentToken = token;
532-
533509
if (skipParsing) {
534510
cmd.addArg(token);
535511
} else if ("--".equals(token)) {
@@ -543,7 +519,6 @@ private void handleToken(final String token) throws ParseException {
543519
} else {
544520
handleUnknownToken(token);
545521
}
546-
547522
if (currentOption != null && !currentOption.acceptsArg()) {
548523
currentOption = null;
549524
}
@@ -560,7 +535,6 @@ private void handleUnknownToken(final String token) throws ParseException {
560535
if (token.startsWith("-") && token.length() > 1 && !stopAtNonOption) {
561536
throw new UnrecognizedOptionException("Unrecognized option: " + token, token);
562537
}
563-
564538
cmd.addArg(token);
565539
if (stopAtNonOption) {
566540
skipParsing = true;
@@ -582,7 +556,6 @@ private boolean isArgument(final String token) {
582556
private boolean isJavaProperty(final String token) {
583557
final String opt = token.isEmpty() ? null : token.substring(0, 1);
584558
final Option option = options.getOption(opt);
585-
586559
return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES);
587560
}
588561

@@ -595,10 +568,8 @@ private boolean isLongOption(final String token) {
595568
if (token == null || !token.startsWith("-") || token.length() == 1) {
596569
return false;
597570
}
598-
599571
final int pos = token.indexOf("=");
600572
final String t = pos == -1 ? token : token.substring(0, pos);
601-
602573
if (!getMatchingLongOptions(t).isEmpty()) {
603574
// long or partial long options (--L, -L, --L=V, -L=V, --l, --l=V)
604575
return true;
@@ -607,7 +578,6 @@ private boolean isLongOption(final String token) {
607578
// -LV
608579
return true;
609580
}
610-
611581
return false;
612582
}
613583

@@ -644,7 +614,6 @@ private boolean isShortOption(final String token) {
644614
if (token == null || !token.startsWith("-") || token.length() == 1) {
645615
return false;
646616
}
647-
648617
// remove leading "-" and "=value"
649618
final int pos = token.indexOf("=");
650619
final String optName = pos == -1 ? token.substring(1) : token.substring(1, pos);

0 commit comments

Comments
 (0)