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

Negatable options do not negate explicit values #1642

Closed
burnnat opened this issue Mar 28, 2022 · 2 comments
Closed

Negatable options do not negate explicit values #1642

burnnat opened this issue Mar 28, 2022 · 2 comments
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@burnnat
Copy link

burnnat commented Mar 28, 2022

When using negatable options, I would expect --flag=true to be equivalent to --flag and --no-flag=true to be equivalent to --no-flag. However, it seems when an explicit value is provided for the option, negation is not taken into account.

I tested with the following code:

@Command(name = "test")
public class TestNegation implements Callable<Integer> {

    @Option(names = {"--flag"}, negatable = true)
    private boolean flag;

    public static void main(String[] args) {
        System.exit(new CommandLine(new TestNegation()).execute(args));
    }

    @Override
    public Integer call() throws Exception {
        System.out.printf("Value: " + flag);
        return 0;
    }
}

And observed these results:

--flag          // Value: true
--no-flag       // Value: false
--flag=true     // Value: true
--no-flag=true  // Value: true (!)
--flag=false    // Value: false
--no-flag=false // Value: false (!)

Is this a bug? If not, some clarification in the documentation on negatable options might be good.

@remkop remkop added type: bug 🐛 theme: parser An issue or change related to the parser labels Mar 29, 2022
@remkop remkop added this to the 4.7 milestone Mar 29, 2022
@remkop
Copy link
Owner

remkop commented Mar 29, 2022

That does look like a bug, thank you for raising this!
I will take a look when I get a chance.

@remkop
Copy link
Owner

remkop commented Mar 31, 2022

This is now fixed in the main branch and will be included in the next release.
Thank you again for raising this!

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