Skip to content

Commit

Permalink
#6 fix search command not showing the results
Browse files Browse the repository at this point in the history
  • Loading branch information
andirady committed Jan 24, 2024
1 parent 6d395b8 commit fb1fa8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/main/java/com/github/andirady/pomcli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/andirady/pomcli/SearchCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand All @@ -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))
Expand All @@ -89,7 +89,7 @@ public void run() {
}

System.console().readLine("\r");
spec.commandLine().getOut().print("\r");
out.printf("\r");
}
}
}
Expand Down

0 comments on commit fb1fa8f

Please sign in to comment.