Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showDefaultValues=true plus defaultValueProvider does not render defaultValues in usage help #616

Closed
sebthom opened this issue Jan 30, 2019 · 6 comments
Milestone

Comments

@sebthom
Copy link

sebthom commented Jan 30, 2019

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")

@remkop
Copy link
Owner

remkop commented Jan 30, 2019

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

@remkop
Copy link
Owner

remkop commented Jan 31, 2019

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.

@remkop remkop added this to the 3.9.3 milestone Jan 31, 2019
remkop added a commit that referenced this issue Jan 31, 2019
@remkop
Copy link
Owner

remkop commented Jan 31, 2019

Fixed in master.
Please verify.

@remkop remkop closed this as completed Jan 31, 2019
remkop added a commit that referenced this issue Jan 31, 2019
@sebthom
Copy link
Author

sebthom commented Jan 31, 2019

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

@remkop
Copy link
Owner

remkop commented Jan 31, 2019

Can you build locally? I don’t 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.

@remkop
Copy link
Owner

remkop commented Feb 1, 2019

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

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants