Modify ↓
Opened 6 years ago
Closed 6 years ago
#17169 closed defect (fixed)
Missing MessageFormat arguments in OptionParser
Reported by: | simon04 | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 19.01 |
Component: | Core | Version: | |
Keywords: | Cc: | michael2402 |
Description
Related to #16866.
A few {0}
/{1}
arguments are missing in OptionParser
(not sure what to insert for xxx
, though):
-
src/org/openstreetmap/josm/tools/OptionParser.java
diff --git a/src/org/openstreetmap/josm/tools/OptionParser.java b/src/org/openstreetmap/josm/tools/OptionParser.java index baaef005b..6f967f516 100644
a b public void runFor(String parameter) { 163 163 parameter = split[1]; 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(); 169 169 } … … public void runFor(String parameter) { 180 180 long count = options.stream().filter(p -> def.equals(p.option)).count(); 181 181 if (count < def.getRequiredCount().min) { 182 182 // min may be 0 or 1 at the moment 183 throw new OptionParseException(tr("{0}: option ''{1}'' is required" ));183 throw new OptionParseException(tr("{0}: option ''{1}'' is required", program, xxx)); 184 184 } else if (count > def.getRequiredCount().max) { 185 185 // max may be 1 or MAX_INT at the moment 186 throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times" ));186 throw new OptionParseException(tr("{0}: option ''{1}'' may not appear multiple times", program, xxx)); 187 187 } 188 188 }); 189 189 … … private AvailableOption findParameter(String optionName) { 221 221 if (alternatives.size() == 1) { 222 222 return alternatives.get(0); 223 223 } else if (alternatives.size() > 1) { 224 throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program ));224 throw new OptionParseException(tr("{0}: option ''{1}'' is ambiguous", program, optionName)); 225 225 } 226 226 } 227 227 throw new OptionParseException(tr("{0}: unrecognized option ''{1}''", program, optionName));
Attachments (0)
Change History (2)
Note:
See TracTickets
for help on using tickets.
OK, that is more difficult. The problem is that an option may have multiple names (short / long)
So:
(1) Make availableOptions a LinkedHashMap
(2) Use
xxx = availableOptions.entrySet().stream().filter(entry -> entry.getValue().equals(def)).map(entry -> entry.getKey()).findFirst().orElse("?")
This will then always find the long option that was registered first.