From fb1fa8f1ca853ca15fb1de56f4e1021a67636056 Mon Sep 17 00:00:00 2001 From: Andi Rady Kurniawan Date: Wed, 24 Jan 2024 13:01:06 +0800 Subject: [PATCH] #6 fix search command not showing the results --- src/main/java/com/github/andirady/pomcli/Main.java | 7 ++++++- .../java/com/github/andirady/pomcli/SearchCommand.java | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/andirady/pomcli/Main.java b/src/main/java/com/github/andirady/pomcli/Main.java index 174e3fc..7419025 100644 --- a/src/main/java/com/github/andirady/pomcli/Main.java +++ b/src/main/java/com/github/andirady/pomcli/Main.java @@ -21,7 +21,12 @@ public class Main { public static void main(String[] args) { - System.exit(createCommandLine(new Main()).execute(args)); + var cli = createCommandLine(new Main()); + try (var out = new PrintWriter(System.out, true)) { + cli.setOut(out); + + System.exit(cli.execute(args)); + } } static CommandLine createCommandLine(Main app) { diff --git a/src/main/java/com/github/andirady/pomcli/SearchCommand.java b/src/main/java/com/github/andirady/pomcli/SearchCommand.java index 64e3f55..9834a0b 100644 --- a/src/main/java/com/github/andirady/pomcli/SearchCommand.java +++ b/src/main/java/com/github/andirady/pomcli/SearchCommand.java @@ -4,7 +4,6 @@ import java.util.Comparator; -import com.github.andirady.pomcli.solrsearch.SolrSearch; import com.github.andirady.pomcli.solrsearch.SolrSearchRequest; import com.github.andirady.pomcli.solrsearch.SolrSearchResult.Document; @@ -61,8 +60,9 @@ public void run() { var resp = solr.search(req).response(); var docs = resp.docs(); + var out = spec.commandLine().getOut(); if (remaining == -1) { - spec.commandLine().getOut().printf("Found %d%n", resp.numFound()); + out.printf("Found %d%n", resp.numFound()); remaining = resp.numFound(); } @@ -72,7 +72,7 @@ public void run() { stream = stream.sorted(Comparator.comparingLong(Document::timestamp).reversed()); } - spec.commandLine().getOut().print( + out.printf("%s", stream.skip(i * 20) .limit(20) .map(d -> format(d)) @@ -89,7 +89,7 @@ public void run() { } System.console().readLine("\r"); - spec.commandLine().getOut().print("\r"); + out.printf("\r"); } } }