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

ArgGroup validation: inconsistent behaviour (4.0.4, #807) #810

Closed
deining opened this issue Sep 9, 2019 · 2 comments
Closed

ArgGroup validation: inconsistent behaviour (4.0.4, #807) #810

deining opened this issue Sep 9, 2019 · 2 comments
Labels
theme: arg-group An issue or change related to argument groups theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@deining
Copy link
Contributor

deining commented Sep 9, 2019

To me, it looks like there is still an issue concerning #807:

import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;

public class ArgTest implements Runnable {

    @ArgGroup(validate = false, exclusive = true, heading = "%nGlobal options:%n")
    protected GlobalOptions globalOptions = new GlobalOptions();

    static class GlobalOptions {
        @Option(names = "-s", description = "ssss", required = true)
        boolean slowClock = false;

        @Option(names = "-v", description = "vvvv", required = false)
        boolean verbose = false;
    }

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

    @Override
    public void run() {
    }
}

When running this code, the programs exits silently, as expected.

Now I'm settings required = true for the second option -v:

@Option(names = "-v", description = "vvvv", required = true)

When running the program after this code change, an error message is printed:

Error: -s, -v are mutually exclusive (specify only one)
Usage: <main class> -sv

Global options:
  -s     ssss
  -v     vvvv

Is this the intended behaviour?

@remkop
Copy link
Owner

remkop commented Sep 10, 2019

Thank you for raising this! I am still looking at this...

One additional problem I found with the example you raised is that if -v and -s are exclusive and both required, and the end user specifies -s -v on the command line, then the GlobalOptions instance gets created twice: once when the -s argument is matched, and another time when -v is matched. The application would not see both slowClock and verbose being true...

So perhaps exclusive should always be false when validate is false... Still thinking about this.

@remkop remkop added this to the 4.0.5 milestone Sep 18, 2019
@remkop remkop added the theme: arg-group An issue or change related to argument groups label Sep 19, 2019
@remkop remkop closed this as completed in f5e67af Oct 10, 2019
@remkop
Copy link
Owner

remkop commented Oct 10, 2019

Thanks again for raising this!

I finally got around to fixing this. I fixed both the validation, and also created and implemented #833 to enforce that ArgGroups with validate=false are automatically changed to be non-exclusive.

@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: arg-group An issue or change related to argument groups theme: parser An issue or change related to the parser type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants