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

Fix and unit test for issue 1834 #1838

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}