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

Behaviour doesn't match documentation for boolean Option arity #1398

Closed
joca-bt opened this issue Jul 29, 2021 · 3 comments · Fixed by #1400
Closed

Behaviour doesn't match documentation for boolean Option arity #1398

joca-bt opened this issue Jul 29, 2021 · 3 comments · Fixed by #1400
Milestone

Comments

@joca-bt
Copy link
Contributor

joca-bt commented Jul 29, 2021

https://picocli.info/apidocs/picocli/CommandLine.Option.html#arity-- says:

  • By default, flags (boolean options) have arity zero
  • By default picocli does not expect boolean options (also called "flags" or "switches") to have a parameter.

However specifying a parameter is not resulting in error by default:

@Command(name = "test")
public class Main implements Runnable {
    @Option(names = { "--option" })
    private boolean option;

    @Override
    public void run() {
    }

    public static void main(String[] args) {
        int exitCode = new CommandLine(new Main()).execute(args);
        System.exit(exitCode);
    }
}

The error only appears when we explicitly add arity = "0" to the above @Option declaration:

option '--option' (<option>) should be specified without 'true' parameter

which, by the documentation, should already be the default.

@remkop
Copy link
Owner

remkop commented Jul 30, 2021

You are correct, the documentation is incorrect.
The default arity for boolean options is actually "0..1" now.

Do you feel like contributing a pull request for this?

@joca-bt
Copy link
Contributor Author

joca-bt commented Jul 30, 2021

Revert the code behaviour or doc?

@remkop
Copy link
Owner

remkop commented Jul 30, 2021

We’ll change the documentation.
There’s no reason to break existing applications that depend on the current behaviour. :-)

remkop added a commit that referenced this issue Aug 4, 2021
remkop added a commit that referenced this issue Aug 4, 2021
@remkop remkop added this to the 4.6.2 milestone Aug 4, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants