Between Tuesday August 20th, 5:00pm and Thursday August 22nd, 8:00am git.uwaterloo.ca will be down for an upgrade to version 10.8.7.

f12581ea by Amin Bandali

Add --pretty option for pretty-printing JSON output

1 parent 5c1ece66
......@@ -44,7 +44,7 @@
@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 @@
@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 @@ protected void initialize(Path outputTxtFile, Path outputJsonFile, Path errorsJs
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 void run() {
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);
ptxt.flush();
ptxt.close();
......