question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixing Required + Non-Required Options in an ArgGroup -- required options not validated

See original GitHub issue

I have a use case similar to other issues – options with sub-options. For example: cli --group=alpha --opt1=1 --group=bravo --opt2=foo

I’m trying something like this:

class Group {
    @Option(names = {"--group"}, required = true) String name;
    @Option(names = {"--opt1"}) int opt1;
    @Option(names = {"--opt2"}) String opt2;
}

@ArgGroup(exclusive = false, multiplicity = "0..*") List<Group> groups;

This almost works:

  • cli --group=alpha --opt1=1 --group=bravo --opt2=foo results in groups = [{name=alpha, opt1=1}, {name=bravo, opt2=foo}]
  • cli --opt1=1 --group=alpha --opt2=foo (weird that --opt1 comes before --group, but allowed) results in groups = [{name=alpha, opt1=1, opt2=foo}]

However, calling cli --opt1=1 results in [{name=null, opt1=2}], with no error. I’d expect an error since the group name is required but not provided, but that doesn’t seem to be the case. Is this supported?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
remkopcommented, Nov 19, 2019

I have been able to reproduce the issue and found the cause: a bug in the validation logic.

1reaction
remkopcommented, Nov 19, 2019

@wjohnson5 Thanks for that background. A feature like this (“repeatable subcommands” https://github.com/remkop/picocli/issues/454 ) is on the TODO list but has been shelved until a clear use case comes up. On the surface it does not look that hard to implement but I haven’t spent the time to analyse in depth. The Click documentation is certainly helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

picocli - a mighty tiny command line interface
Mixing Options and Positional Parameters. From picocli 2.0, positional parameters can be specified anywhere on the command line, they no longer need to...
Read more >
Using Picocli, how do I require a positional argument and then ...
How do I handle that? I tried the following, but I get an error: ArgGroup has no options or positional parameters, and no...
Read more >
clap - Rust - Docs.rs
Used to set all the options and relationships that define a valid argument for the program. ArgGroup. ArgGroup s are a family of...
Read more >
Device Parameter Validation Request - IBM
HCD validates the following definitions: The parameter is supported for the device type; Required parameters are specified; The type of private parameter value ......
Read more >
Quickstart - webargs 8.2.0 documentation
from webargs import fields, validate user_args = { # Required arguments "username": ... raise ValidationError("User does not exist") args = {"id": fields.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found