Picocli: showDefaultValues=true plus defaultValueProvider does not render defaultValues in usage help

Created on 30 Jan 2019  路  6Comments  路  Source: remkop/picocli

Specifying the default value of an option via an IDefaultValueProvider and setting showDefaultValues = true does not display the default vaulue as part of the standard usage help.

Example Code:

@Command(name = "foo", //
    mixinStandardHelpOptions = true, //
    defaultValueProvider = FooCommandDefaultValueProvider.class, //
    showDefaultValues = true, //
)
public class FooCommand implements Runnable {

    public static class FooCommandDefaultValueProvider implements IDefaultValueProvider {
        @Override
        public String defaultValue(final ArgSpec argSpec) throws Exception {
            if ("DURATION".equals(argSpec.paramLabel())) {
                return "1200";
            }
            return null;
        }
    }

    @Option( //
        names = {"-d", "--duration"}, paramLabel = "DURATION", //
        description = { "The duration, in seconds." }, //
        arity = "1", //
        required = false //
    )
    protected Integer duration;
}

Only when I additionally set @Option(showDefaultValue=Help.Visibility.ALWAYS) for the respective option the value is displayed or when I explicitly set a default value directly via @Option(defaultValue="1200")

bug

All 6 comments

Thanks for the bug report! I'll take a look as soon as I can.

I found the cause.
In ArgSpec.internalShowDefaultValue(boolean) the logic checks whether a default value exists, and this does not take the defaultValueProvider into account.

I'll have a fix for this shortly.

Fixed in master.
Please verify.

@remkop thanks for the fast fix! where can I find the snapshot artifacts to verify the fix?

Can you build locally? I don鈥檛 publish snapshots but one of the Gradle tasks is to publish to the local Maven repo. You can then refer to the snapshot build in your project.

Picocli 3.9.3 has been released. This includes a fix for this issue.

Enjoy!

Was this page helpful?
0 / 5 - 0 ratings