From acbb2104cd089c1481c77ca376a6994cb15d1605 Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Sat, 19 Aug 2023 19:35:55 -0500 Subject: [PATCH] converter: Support writing to stdout --- tools/alys_converter.cr | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/alys_converter.cr b/tools/alys_converter.cr index 0f2154f..a8c5bdc 100644 --- a/tools/alys_converter.cr +++ b/tools/alys_converter.cr @@ -458,6 +458,15 @@ enum Format end end +def convert(*, from reader : EventReader, to dest : IO, format : Format, indent_json : Bool) + case format + when Format::JSON + CustomJsonEventWriter.write from: reader, to: dest, indent_json: indent_json + when Format::PProf + PProfEventWriter.write from: reader, to: dest + end +end + def run indent_json = false symbolizer = nil @@ -506,12 +515,11 @@ def run event = File.open source do |source_file| source = MessagePack::IOUnpacker.new source_file reader = EventReader.new source, symbolizer - File.open dest, "w" do |dest_file| - case format - when Format::JSON - CustomJsonEventWriter.write from: reader, to: dest_file, indent_json: indent_json - when Format::PProf - PProfEventWriter.write from: reader, to: dest_file + if dest == "-" + convert from: reader, to: STDOUT, format: format, indent_json: indent_json + else + File.open dest, "w" do |dest_file| + convert from: reader, to: dest_file, format: format, indent_json: indent_json end end end -- 2.45.2