question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
remkopcommented, Feb 1, 2019

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

Enjoy!

1reaction
remkopcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DefaultValues of react-hook-form is not setting the values to ...
The problem is that during the first render, users is the useState hook's initial value, which is null . The value only changes...
Read more >
Generated defaultValues are not applied after first render #1558
I have a form that includes controlled components (several Material-UI checkboxes). By specifying defaultValues, I am able to reset the form ...
Read more >
useForm - watch - Simple React forms validation
When defaultValue is not defined, the first render of watch will return undefined because it is called before register . It's recommend to...
Read more >
Linux useradd command help and examples - Computer Hope
The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not...
Read more >
Change Command Default (CHGCMDDFT) - IBM
This procedure allows the user to use the original IBM-supplied command defaults when necessary and ensures that changes made to the copied commands...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found