Skip to content

Commit

Permalink
[#1629] Omit empty braces in prompt for interactive options without d…
Browse files Browse the repository at this point in the history
…escription

Closes #1629
  • Loading branch information
remkop committed Mar 7, 2022
1 parent 3f989ef commit fe4e8fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Picocli 4.7.0 introduced a `sortSynopsis = false` attribute to let the synopsis
* [#1572] Enhancement: Remove redundant braces in ArgGroup synopsis.
* [#1602] Enhancement: Fix incorrect debug output for add/removeAlias.
* [#1603] Enhancement: Improve debug tracing information for help requests and command execution.
* [#1629] Enhancement: Omit empty braces in standard prompt for interactive options without description. Thanks to [Andreas Deininger](https://github.com/deining) for raising this.
* [#1615][#1616] Bugfix: `getCJKAdjustedLength()` no longer miscalculates for supplementary code points. Thanks to [gwalbran](https://github.com/gwalbran) for the pull request.
* [#1575] Bugfix: Synopsis should not cluster boolean options if `posixClusteredShortOptionsAllowed` is set to false.
* [#1298] DOC: Publish all-in-one javadoc for all picocli modules.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -14742,7 +14742,9 @@ private boolean assertNoMissingParameters(ArgSpec argSpec, Range arity, Stack<St

char[] readUserInput(ArgSpec argSpec) {
String name = argSpec.isOption() ? ((OptionSpec) argSpec).longestName() : "position " + position;
String prompt = !empty(argSpec.prompt()) ? argSpec.prompt() : String.format("Enter value for %s (%s): ", name, str(argSpec.description(), 0));
String desc = str(argSpec.description(), 0);
String standardPrompt = empty(desc) ? String.format("Enter value for %s: ", name) : String.format("Enter value for %s (%s): ", name, desc);
String prompt = empty(argSpec.prompt()) ? standardPrompt : argSpec.prompt();
try {
Tracer t = tracer();
if (t.isDebug()) {
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/picocli/InteractiveArgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ class App {
}
}

@Test
public void testInteractiveOptionWithoutDescriptionStandardPrompt() {
class App {
@Option(names = "-x", interactive = true) int x;
}

PrintStream out = System.out;
InputStream in = System.in;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
System.setIn(new ByteArrayInputStream("123".getBytes()));

App app = new App();
CommandLine cmd = new CommandLine(app);
cmd.parseArgs("-x");

assertEquals("Enter value for -x: ", baos.toString());
assertEquals(123, app.x);
} finally {
System.setOut(out);
System.setIn(in);
}
}

@Test
public void testInteractiveOptionReadsFromStdInWithCustomPrompt() {
class App {
Expand Down

0 comments on commit fe4e8fa

Please sign in to comment.