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

defaultValue="false" + usageHelp/versionHelp=true does not cause detection of missing parameters #608

Closed
pietrobraione opened this issue Jan 16, 2019 · 3 comments
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@pietrobraione
Copy link

Let us consider this situation:

class App {
  @Option(names = "-h", usageHelp = true, defaultValue = "false")
  boolean helpAsked;

  @Option(names = "-V", versionHelp = true, defaultValue = "false")
  boolean helpAsked;

  @Parameters
  String compulsoryParameter;
}

and the code:

CommandLine commandLine = new CommandLine(new App());
commandLine.parse(new String[0]);
System.out.println("Success!");

The code prints "Success!", but it should raise MissingParameterException. By a superficial debugging of the picocli code it seems that the method CommandLine.Parser.applyDefault(IDefaultValueProvider, ArgSpec, List<ArgSpec>) does not set the correct default value to the usage and version help options when the defaultValue attribute is present in the @Option annotation. Thus picocli behaves as if the two options were active. By removing the defaultValue attributes everything works correctly.

@remkop remkop added this to the 3.9.2 milestone Jan 16, 2019
remkop added a commit that referenced this issue Jan 16, 2019
…ectly prevents validation of required options and positional parameters
@remkop
Copy link
Owner

remkop commented Jan 16, 2019

Thank you for the bug report!
This has been fixed in master.
Can you verify?

@remkop remkop closed this as completed Jan 16, 2019
@pietrobraione
Copy link
Author

...give me some more time, I am too busy right now, but I will check it soon. Sorry for that and thank you for the quick fix.

@remkop
Copy link
Owner

remkop commented Jan 24, 2019

No problem. Picocli 2.9.2 has been released which includes this fix, but please let me know if there’s any issue. Enjoy!

@remkop remkop added the theme: parser An issue or change related to the parser label Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants