Skip to content

Commit

Permalink
[#1380] Updated fix for requiredOptionMarker displayed on ArgGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmede41 committed Dec 17, 2021
1 parent 914a95d commit fac6cdc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,21 @@
class TestingClassExclusiveTrue {

@ArgGroup(exclusive = true, multiplicity = "0..1")
private TestingClassExclusiveTrue.ExclusiveOptions exclusive;
protected TestingClassExclusiveTrue.ExclusiveOptions exclusive;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public ExclusiveOptions getExclusive() {
return this.exclusive;
}

private static class ExclusiveOptions {
@Option(names = {"-s", "--silent"}, description = "Silent mode", required = false)
private boolean silent;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getSilent() {
return this.silent;
}
protected boolean silent;

@Option(names = {"-v", "--verbose"}, description = "Verbose mode", required = false)
private boolean verbose;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getVerbose() {
return this.verbose;
}
protected boolean verbose;

@Option(names = {"-j", "--json"}, description = "JSON printing", required = false)
private boolean json;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getJson(){
return this.json;
}

protected boolean json;
}
}

Expand All @@ -67,55 +42,27 @@ public boolean getJson(){
class TestingClassExclusiveFalse {

@ArgGroup(exclusive = false, multiplicity = "0..1")
private TestingClassExclusiveFalse.ExclusiveOptions exclusive;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public ExclusiveOptions getExclusive() {
return this.exclusive;
}
protected TestingClassExclusiveFalse.ExclusiveOptions exclusive;

private static class ExclusiveOptions {
@Option(names = {"-s", "--silent"}, description = "Silent mode", required = false)
private boolean silent;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getSilent() {
return this.silent;
}
protected boolean silent;

@Option(names = {"-v", "--verbose"}, description = "Verbose mode", required = false)
private boolean verbose;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getVerbose() {
return this.verbose;
}
protected boolean verbose;

@Option(names = {"-j", "--json"}, description = "JSON printing", required = false)
private boolean json;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getJson(){
return this.json;
}
protected boolean json;
}
}

/**
* JUnit testing class for issue 1380 // CS427 https://github.com/remkop/picocli/issues/1380
* JUnit testing class for issue#1380 // CS427 https://github.com/remkop/picocli/issues/1380
*/
public class Issue1380Test {

/**
* JUnit test class for issue 1380 with exclusive set to true // CS427 https://github.com/remkop/picocli/issues/1380
* JUnit test class for issue#1380 with exclusive set to true // CS427 https://github.com/remkop/picocli/issues/1380
*/
@Test
public void testingWithExclusiveTrue() {
Expand All @@ -131,11 +78,10 @@ public void testingWithExclusiveTrue() {
" -v, --verbose Verbose mode\n";

assertEquals(expectedText, returnedText);

}

/**
* JUnit test class for issue 1380 with exclusive set to false // CS427 https://github.com/remkop/picocli/issues/1380
* JUnit test class for issue#1380 with exclusive set to false// CS427 https://github.com/remkop/picocli/issues/1380
*/
@Test
public void testingWithExclusiveFalse() {
Expand All @@ -150,6 +96,5 @@ public void testingWithExclusiveFalse() {
" -v, --verbose Verbose mode\n";

assertEquals(expectedText, returnedText);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,29 @@
class TestingClass {

@ArgGroup(exclusive = true, multiplicity = "0..1")
private TestingClass.ExclusiveOptions exclusive;
protected TestingClass.ExclusiveOptions exclusive;

public TestingClass.ExclusiveOptions getExclusive() {
return this.exclusive;
}
private static class ExclusiveOptions {
@Option(names = {"-h", "--help"}, descriptionKey = "help.message", required = false)
private boolean showHelp;
protected boolean showHelp;

@Option(names = {"-j", "--json"}, descriptionKey = "json.message", required = false)
private boolean isJson;

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getshowHelp(){ return this.showHelp; }

/**
* Added getters to satisfy PMF and findBug requirements
*/
public boolean getJson(){ return this.isJson; }
protected boolean isJson;

}
}


@Ignore
/**
* JUnit testing class for issue 1420 // CS427 https://github.com/remkop/picocli/issues/1420
* JUnit testing class for issue#1420 // CS427 https://github.com/remkop/picocli/issues/1420
*/
public class Issue1420Test {

/**
* JUnit test class for issue 1420 with resourceBundle // CS427 https://github.com/remkop/picocli/issues/1420
* JUnit test class for issue#1420 with resourceBundle // CS427 https://github.com/remkop/picocli/issues/1420
*/
@Test
public void testingWithResourceBundle1() {
Expand All @@ -65,6 +54,5 @@ public void testingWithResourceBundle1() {
" -j, --json Set json export-on\n";

assertEquals(expectedText, returnedText);

}
}
12 changes: 0 additions & 12 deletions qaplug_result.html

This file was deleted.

24 changes: 12 additions & 12 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -8528,7 +8528,7 @@ public abstract static class ArgSpec {

// parser fields
private boolean required;
private boolean optionIsNotRequired;
private boolean originallyRequired;
private final boolean interactive;
private final boolean echo;
private final String prompt;
Expand Down Expand Up @@ -8581,7 +8581,7 @@ private <T extends Builder<T>> ArgSpec(Builder<T> builder) {
annotatedElement = builder.annotatedElement;
defaultValue = NO_DEFAULT_VALUE.equals(builder.defaultValue) ? null : builder.defaultValue;
required = builder.required;
optionIsNotRequired = builder.optionIsNotRequired;
originallyRequired = builder.originallyRequired;
toString = builder.toString;
getter = builder.getter;
setter = builder.setter;
Expand Down Expand Up @@ -8638,11 +8638,11 @@ void applyInitialValue(Tracer tracer) {
}
}

/** Returns whether this is a required option or positional parameter without a default value.
* If this argument is part of a {@linkplain ArgGroup group}, this method returns whether this argument is required <em>within the group</em> (so it is not necessarily a required argument for the command).
* @see Option#optionIsNotRequired() */
public boolean optionIsNotRequired(){
return optionIsNotRequired;
/** Returns the originally required option, regardless of whether the option is used in an exclusive group or not.
* @since 4.7.0
* @see Option#required() */
public boolean originallyRequired(){
return originallyRequired;
}

/** Returns whether this is a required option or positional parameter without a default value.
Expand Down Expand Up @@ -9196,7 +9196,7 @@ abstract static class Builder<T extends Builder<T>> {
private String[] description;
private String descriptionKey;
private boolean required;
private boolean optionIsNotRequired;
private boolean originallyRequired;
private boolean interactive;
private boolean echo;
private String prompt;
Expand Down Expand Up @@ -9234,7 +9234,7 @@ abstract static class Builder<T extends Builder<T>> {
description = original.description;
descriptionKey = original.descriptionKey;
required = original.required;
optionIsNotRequired = original.optionIsNotRequired;
originallyRequired = original.originallyRequired;
interactive = original.interactive;
echo = original.echo;
prompt = original.prompt;
Expand Down Expand Up @@ -10132,8 +10132,8 @@ public static class ArgGroupSpec implements IOrdered {
if (!arg.required()) {
modifiedArgs += sep + (arg.isOption() ? ((OptionSpec) arg).longestName() : (arg.paramLabel() + "[" + ((PositionalParamSpec) arg).index() + "]"));
sep = ",";
//Keep initial required as optionIsNotRequired for Issue#1380 https://github.com/remkop/picocli/issues/1380
arg.optionIsNotRequired = true;
//Keep initial required as originallyRequired for Issue#1380 https://github.com/remkop/picocli/issues/1380
arg.originallyRequired = true;
arg.required = true;
}
}
Expand Down Expand Up @@ -16128,7 +16128,7 @@ public Text[][] render(OptionSpec option, IParamLabelRenderer paramLabelRenderer
String longOption = join(names, shortOptionCount, names.length - shortOptionCount, ", ");
Text longOptionText = createLongOptionText(option, paramLabelRenderer, scheme, longOption);

String requiredOption = !option.optionIsNotRequired() && option.required() ? requiredMarker : "";
String requiredOption = !option.originallyRequired() && option.required() ? requiredMarker : "";
return renderDescriptionLines(option, scheme, requiredOption, shortOption, longOptionText);
}

Expand Down

0 comments on commit fac6cdc

Please sign in to comment.