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) {  
    163163                        parameter = split[1];
    164164                    } else {
    165165                        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));
    167167                        }
    168168                        parameter = toHandle.removeFirst();
    169169                    }
    public void runFor(String parameter) {  
    180180            long count = options.stream().filter(p -> def.equals(p.option)).count();
    181181            if (count < def.getRequiredCount().min) {
    182182                // 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));
    184184            } else if (count > def.getRequiredCount().max) {
    185185                // 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));
    187187            }
    188188        });
    189189
    private AvailableOption findParameter(String optionName) {  
    221221            if (alternatives.size() == 1) {
    222222                return alternatives.get(0);
    223223            } 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));
    225225            }
    226226        }
    227227        throw new OptionParseException(tr("{0}: unrecognized option ''{1}''", program, optionName));

Attachments (0)

Change History (2)

comment:1 by michael2402, 6 years ago

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.

Last edited 6 years ago by michael2402 (previous) (diff)

comment:2 by simon04, 6 years ago

Resolution: fixed
Status: newclosed

In 14640/josm:

fix #17169 - Missing MessageFormat arguments in OptionParser

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.