Verified Commit f12581ea authored by Amin Bandali's avatar Amin Bandali
Browse files

Add --pretty option for pretty-printing JSON output

parent 5c1ece66
......@@ -44,7 +44,7 @@ import picocli.CommandLine.Option;
@Command(showDefaultValues = true)
public abstract class CatalystCommand {
protected transient Result r;
protected transient Gson gson, gsonPretty;
protected transient Gson gson;
protected transient AtomicInteger errorCount;
protected transient Writer wtxt, wjson, ejson;
protected transient PrintWriter ptxt;
......@@ -88,6 +88,9 @@ public abstract class CatalystCommand {
@Option(names = "--parallel", description = "Parallel mode (use parallel streams)")
protected boolean parallel;
@Option(names = "--pretty", description = "Pretty-print JSON output to make it more human-readable")
protected boolean pretty;
final transient protected Map errors = parallel ?
Collections.synchronizedMap(new LinkedHashMap<Path, CatalystError>()) :
new LinkedHashMap<Path, CatalystError>();
......@@ -96,8 +99,7 @@ public abstract class CatalystCommand {
r = new Result();
r.options = this;
r.results = new ArrayList<CorpusResult>();
gson = new Gson();
gsonPretty = new GsonBuilder().setPrettyPrinting().create();
gson = pretty ? new Gson() : new GsonBuilder().setPrettyPrinting().create();
errorCount = new AtomicInteger();
wtxt = setupWriter(outputTxtFile, true);
wjson = setupWriter(outputJsonFile, true);
......@@ -71,7 +71,7 @@ public final class SSR extends CatalystCommand implements Runnable {
pln(String.format("total elapsed time: %dms", r.total_elapsed_time));
writerWriteFlushClose(wjson, gson.toJson(r), oj);
writerWriteFlushClose(ejson, gsonPretty.toJson(errors), ej);
writerWriteFlushClose(ejson, gson.toJson(errors), ej);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment