Skip to content

Commit

Permalink
Add duplicate negated option check (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbieOrange authored and remkop committed May 8, 2020
1 parent d9837bf commit 6a74252
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/picocli/CommandLine.java
Expand Up @@ -6001,6 +6001,13 @@ public CommandSpec addOption(OptionSpec option) {
if (existing != null) { /* was: && !existing.equals(option)) {*/ // since 4.0 ArgGroups: an option cannot be in multiple groups
throw DuplicateOptionAnnotationsException.create(existingName, option, existing);
}
String negatedName = negatableOptionTransformer().makeNegative(name, this);
String existingNegatedName = optionsByNameMap.getCaseSensitiveKey(negatedName);
OptionSpec existingNegated = negatedOptionsByNameMap.get(negatedName);
if (existingNegated == null) { existingNegated = optionsByNameMap.get(negatedName); }
if (existingNegated != null) {
throw DuplicateOptionAnnotationsException.create(existingNegatedName, option, existingNegated);
}
if (name.length() == 2 && name.startsWith("-")) { posixOptionsByKeyMap.put(name.charAt(1), option); }
}
options.add(option);
Expand Down

0 comments on commit 6a74252

Please sign in to comment.