Skip to content

Commit

Permalink
Simplified CommandSpec#validateSubcommandName(…) by returning ASAP wh…
Browse files Browse the repository at this point in the history
…en the correct return value is first known
  • Loading branch information
rgoldberg authored and remkop committed Jan 3, 2022
1 parent 9427525 commit 4984dd3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6499,16 +6499,21 @@ public CommandLine removeSubcommand(String name) {
}

private String validateSubcommandName(String name, CommandSpec subSpec) {
String result = name == null ? subSpec.name : name; // NOTE: check subSpec.name field, not subSpec.name()!
if (result == null && !subSpec.aliases.isEmpty()) {
if (name != null) {
return name;
}
if (subSpec.name != null) { // NOTE: check subSpec.name field, not subSpec.name()!
return subSpec.name;
}
if (!subSpec.aliases.isEmpty()) {
Iterator<String> iter = subSpec.aliases.iterator();
result = iter.next();
String result = iter.next();
iter.remove();
if (result != null) {
return result;
}
}
if (result == null) {
throw new InitializationException("Cannot add subcommand with null name to " + this.qualifiedName());
}
return result;
throw new InitializationException("Cannot add subcommand with null name to " + qualifiedName());
}

private void initCommandHierarchyWithResourceBundle(String bundleBaseName, ResourceBundle rb) {
Expand Down

0 comments on commit 4984dd3

Please sign in to comment.