Changeset 14640 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-01-04T23:44:59+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OptionParser.java
r14441 r14640 42 42 public OptionParser addShortAlias(String optionName, String shortName) { 43 43 if (!shortName.matches("\\w")) { 44 throw new IllegalArgumentException("Short name " + shortName + "must be one character");44 throw new IllegalArgumentException("Short name '" + shortName + "' must be one character"); 45 45 } 46 46 if (availableOptions.containsKey("-" + shortName)) { 47 throw new IllegalArgumentException("Short name " + shortName + "is already used");47 throw new IllegalArgumentException("Short name '" + shortName + "' is already used"); 48 48 } 49 49 AvailableOption longDefinition = availableOptions.get("--" + optionName); … … 70 70 private void checkOptionName(String optionName) { 71 71 if (!optionName.matches("\\w([\\w-]*\\w)?")) { 72 throw new IllegalArgumentException("Illegal option name: " + optionName);72 throw new IllegalArgumentException("Illegal option name: '" + optionName + "'"); 73 73 } 74 74 if (availableOptions.containsKey("--" + optionName)) { 75 throw new IllegalArgumentException("The option --" + optionName + "is already registered");75 throw new IllegalArgumentException("The option '--" + optionName + "' is already registered"); 76 76 } 77 77 } … … 164 164 } else { 165 165 if (toHandle.isEmpty() || "--".equals(toHandle.getFirst())) { 166 throw new OptionParseException(tr("{0}: option ''{1}'' requires an argument", program ));166 throw new OptionParseException(tr("{0}: option ''{1}'' requires an argument", program, optionName)); 167 167 } 168 168 parameter = toHandle.removeFirst(); … … 179 179 availableOptions.values().stream().distinct().forEach(def -> { 180 180 long count = options.stream().filter(p -> def.equals(p.option)).count(); 181 String optionName = availableOptions.entrySet().stream() 182 .filter(entry -> def.equals(entry.getValue())) 183 .map(Entry::getKey) 184 .findFirst() 185 .orElse("?"); 181 186 if (count < def.getRequiredCount().min) { 182 187 // min may be 0 or 1 at the moment 183 throw new OptionParseException(tr("{0}: option ''{1}'' is required" ));188 throw new OptionParseException(tr("{0}: option ''{1}'' is required", program, optionName)); 184 189 } else if (count > def.getRequiredCount().max) { 185 190 // max may be 1 or MAX_INT at the moment 186 throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times" ));191 throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times", program, optionName)); 187 192 } 188 193 }); … … 222 227 return alternatives.get(0); 223 228 } else if (alternatives.size() > 1) { 224 throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program ));229 throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program, optionName)); 225 230 } 226 231 }
Note:
See TracChangeset
for help on using the changeset viewer.