Skip to content

Commit

Permalink
Check for cli parameters to not fail picocli unit test testIssue1027R…
Browse files Browse the repository at this point in the history
…epeatingPositionalParamsWithMinMultiplicity.
  • Loading branch information
MikeTheSnowman committed Jul 6, 2023
1 parent e4f29c2 commit 692056f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions fcli-common/src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13096,26 +13096,39 @@ void validate(CommandLine commandLine) {
private boolean isRequiredArgGroup(ArgGroupSpec spec) {
if ( spec.exclusive() ) {
// Only return true if all options and subgroups are considered required
return isAllOptionsRequired(spec) && isAllSubGroupsRequired(spec);
return isAllOptionsRequired(spec) && isAllSubGroupsRequired(spec) && isAllParamsRequired(spec);
} else {
// Return true if at least one option or subgroup is required
return isAnyOptionRequired(spec) || isAnySubGroupRequired(spec);
return isAnyOptionRequired(spec) || isAnySubGroupRequired(spec) || isAnyParamRequired(spec);
}
}

private boolean isAllOptionsRequired(ArgGroupSpec spec) {
for ( OptionSpec option : spec.options() ) {
if ( !option.required() ) { return false; }
}
return true;
}

private boolean isAnyOptionRequired(ArgGroupSpec spec) {
for ( OptionSpec option : spec.options() ) {
if ( option.required() ) { return true; }
}
return false;
}

public boolean isAllParamsRequired(ArgGroupSpec spec) {
for ( PositionalParamSpec param : spec.positionalParameters() ){
if( !param.required() ){return false;}
}
return true;
}
public boolean isAnyParamRequired(ArgGroupSpec spec) {
for ( PositionalParamSpec param : spec.positionalParameters() ){
if( param.required() ){return true;}
}
return false;
}

private boolean isAllSubGroupsRequired(ArgGroupSpec spec) {
for ( ArgGroupSpec subgroup : spec.subgroups() ) {
Expand Down

0 comments on commit 692056f

Please sign in to comment.