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

Duplicate negated options are accepted #1022

Closed
ifsheldon opened this issue May 3, 2020 · 1 comment · Fixed by #1029
Closed

Duplicate negated options are accepted #1022

ifsheldon opened this issue May 3, 2020 · 1 comment · Fixed by #1029
Milestone

Comments

@ifsheldon
Copy link

ifsheldon commented May 3, 2020

During the tests for the case-insensitive issue, it seems that I found one somewhat interesting issue(bug?).

    @Test
    public void testDuplicateNegatedOptionsRejected()
    {
        @CommandLine.Command(name = "negatable-options-demo")
        class NegatableOptionsDemo
        {
            @CommandLine.Option(names = "--verbose", negatable = true)
            boolean verbose= false;
            @CommandLine.Option(names = "--no-verbose")
            boolean nverbose = false;
        }
        NegatableOptionsDemo d = new NegatableOptionsDemo();
        CommandLine cmd = new CommandLine(d);
        cmd.execute("--verbose");
        assertTrue(d.verbose);
        assertFalse(d.nverbose);
        cmd.execute("--no-verbose");
        assertFalse(d.verbose); // it seems both fields have been set
        assertTrue(d.nverbose); // it seems both fields have been set
    }

I think this test should throw a duplication execption, but it passed.

@remkop
Copy link
Owner

remkop commented May 3, 2020

Nice find, thank you!

Yes, this is a bug. It seems that when a negatable option is added, picocli checks that the option name and its negative form don't exist. However, when a non-negatable option is added, this check is not performed.

@remkop remkop changed the title Duplicate nagetaed options are acceptable Duplicate negated options are accepted May 3, 2020
@remkop remkop added this to the 4.3 milestone May 7, 2020
remkop pushed a commit that referenced this issue May 8, 2020
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