cbeust / jcommander

Command line parsing framework for Java
Apache License 2.0
1.96k stars 334 forks source link

JCommander#addCommand does not copy the custom `IUsageFormatter` #487

Open fbiville opened 4 years ago

fbiville commented 4 years ago

It seems currently impossible to have a custom IUsageFormatter that propagates to commands:

Here is the current stable version of the canonical addCommand (v1.78).

    public void addCommand(String name, Object object, String... aliases) {
        JCommander jc = new JCommander(options);
        jc.addObject(object);
        jc.createDescriptions();
        jc.setProgramName(name, aliases);
        ProgramName progName = jc.programName;
        commands.put(progName, jc);
        // aliases [...]
    }

Every added command will be associated with a JCommander instance set with DefaultUsageFormatter.

I assume the fix would consist in setting the custom IUsageFormatter in the associated JCommander.Options instance?