Skip to content

Commit

Permalink
Fix and unit test for issue 1834.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTheSnowman authored and remkop committed Oct 16, 2022
1 parent 05ec0e8 commit b910763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5995,13 +5995,13 @@ private Model() {}
* @since 4.0
*/
public interface IScope extends IGetter, ISetter {}
/** This interface provides access to an {@link IScope} instance.

/** This interface provides access to an {@link IScope} instance.
* @since 4.7
*/
public interface IScoped {
/** Get the {@link IScope} instance.
*
*
* @return {@link IScope} instance */
IScope getScope();
}
Expand Down Expand Up @@ -9176,8 +9176,8 @@ private String defaultValueFromProvider() {
* @return whether this argument applies to all descendent subcommands of the command where it is defined
* @since 4.3 */
public ScopeType scopeType() { return scopeType; }
/** Check whether the {@link #getValue()} method is able to get an actual value from the current {@link #getter()}.

/** Check whether the {@link #getValue()} method is able to get an actual value from the current {@link #getter()}.
* @since 4.7 */
public boolean isValueGettable() {
if (getter instanceof IScoped) {
Expand Down Expand Up @@ -15754,14 +15754,17 @@ static Text concatOptionText(String prefix, Text text, Help.ColorScheme colorSch
Text name = colorScheme.optionText(nameString);
Text param = parameterLabelRenderer.renderParameterLabel(option, colorScheme.ansi(), colorScheme.optionParamStyles);
text = text.concat(prefix);

// related: Interpreter#getActualTypeConverter special logic for interactive char[] options... (also: #648)
boolean treatAsSingleValue = char[].class.equals(option.type()) && option.interactive(); // #1834
if (option.required()) { // e.g., -x=VAL
text = text.concat(name).concat(param).concat("");
if (option.isMultiValue()) { // e.g., -x=VAL [-x=VAL]...
if (option.isMultiValue() && !treatAsSingleValue) { // e.g., -x=VAL [-x=VAL]...
text = text.concat(" [").concat(name).concat(param).concat("]...");
}
} else {
text = text.concat("[").concat(name).concat(param).concat("]");
if (option.isMultiValue()) { // add ellipsis to show option is repeatable
if (option.isMultiValue() && !treatAsSingleValue) { // add ellipsis to show option is repeatable
text = text.concat("...");
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/picocli/HelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5180,4 +5180,14 @@ public Text[][] render(OptionSpec option, IParamLabelRenderer ignored, ColorSche
String actual = cmd.getUsageMessage();
assertEquals(expected, actual);
}

@Test
public void testIssue1834SynopsisForCharArrayOption() {
@Command() class App {
@Option(names = {"--password", "-p"}, interactive = true, echo = false, arity = "0..1", required = true)
private char[] password;;
}
Help help = new Help(new App());
assertEquals("<main class> -p[=<password>]" + LINESEP, help.synopsis(0));
}
}

0 comments on commit b910763

Please sign in to comment.