Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 061bf14

Browse files
committed
Don't print new lines when no data
1 parent 580b890 commit 061bf14

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellVerboseIntegrationTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,24 @@ public void shouldShowTheNumberOfRows() throws CommandException {
228228
String actual = linePrinter.output();
229229
assertThat(actual, containsString("3 rows available"));
230230
}
231+
232+
@Test
233+
public void shouldNotContainUnnecessaryNewLines() throws CommandException {
234+
//when
235+
shell.execute("UNWIND [1,2,3] AS row RETURN row");
236+
237+
//then
238+
String actual = linePrinter.output();
239+
assertThat(actual,
240+
containsString( String.format(
241+
"+-----+%n" +
242+
"| row |%n" +
243+
"+-----+%n" +
244+
"| 1 |%n" +
245+
"| 2 |%n" +
246+
"| 3 |%n" +
247+
"+-----+%n" +
248+
"%n" +
249+
"3 rows available after")));
250+
}
231251
}

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/PrettyPrinter.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public void format(@Nonnull final BoltResult result, LinePrinter linePrinter) {
2828
numberOfRows = outputFormatter.formatAndCount(result, linePrinter);
2929
}
3030

31-
if (capabilities.contains(INFO)) linePrinter.printOut(outputFormatter.formatInfo(result.getSummary()));
32-
if (capabilities.contains(PLAN)) linePrinter.printOut(outputFormatter.formatPlan(result.getSummary()));
33-
if (capabilities.contains(FOOTER)) linePrinter.printOut(outputFormatter.formatFooter(result, numberOfRows));
34-
if (capabilities.contains(STATISTICS)) linePrinter.printOut(statisticsCollector.collect(result.getSummary()));
31+
if (capabilities.contains(INFO)) printIfNotEmpty(outputFormatter.formatInfo(result.getSummary()), linePrinter);
32+
if (capabilities.contains(PLAN)) printIfNotEmpty(outputFormatter.formatPlan(result.getSummary()), linePrinter);
33+
if (capabilities.contains(FOOTER)) printIfNotEmpty(outputFormatter.formatFooter(result, numberOfRows), linePrinter);
34+
if (capabilities.contains(STATISTICS)) printIfNotEmpty(statisticsCollector.collect(result.getSummary()), linePrinter);
3535
}
3636

3737
// Helper for testing
@@ -41,6 +41,12 @@ String format(@Nonnull final BoltResult result) {
4141
return sb.toString();
4242
}
4343

44+
private void printIfNotEmpty( String s, LinePrinter linePrinter ) {
45+
if (!s.isEmpty()) {
46+
linePrinter.printOut( s );
47+
}
48+
}
49+
4450
private OutputFormatter selectFormatter(PrettyConfig prettyConfig) {
4551
if (prettyConfig.format == Format.VERBOSE) {
4652
return new TableOutputFormatter(prettyConfig.wrap, prettyConfig.numSampleRows);

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/TableOutputFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private int formatResultAndCountRows(String[] columns,
7272
output.printOut(formatRecord(builder, columnSizes, records.next()));
7373
numberOfRows++;
7474
}
75-
output.printOut(dashes);
75+
output.printOut(String.format("%s%n", dashes));
7676
return numberOfRows;
7777
}
7878

cypher-shell/src/test/java/org/neo4j/shell/prettyprint/TableOutputFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void wrapContent()
290290
"| \"eee |",
291291
"| ee\" |",
292292
"+------+",
293-
"")));
293+
NEWLINE)));
294294
}
295295

296296
@Test
@@ -313,7 +313,7 @@ public void truncateContent()
313313
"| \"dd… |",
314314
"| \"ee… |",
315315
"+------+",
316-
"")));
316+
NEWLINE)));
317317
}
318318

319319
@Test

0 commit comments

Comments
 (0)