From 5b4203d7fcffa646dcaf0466d64479c35e4ea4b7 Mon Sep 17 00:00:00 2001 From: Andre Sencioles Date: Fri, 26 Aug 2022 17:01:02 +1200 Subject: [PATCH] Support stdout output --- export/export.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/export/export.go b/export/export.go index df63e07..ea09a62 100644 --- a/export/export.go +++ b/export/export.go @@ -61,11 +61,17 @@ func Run(ctx context.Context, conf *flags.Flags) { conf.Fields = strings.Split(conf.Fieldlist, ",") } - outfile, err := os.Create(conf.Outfile) - if err != nil { - log.Fatalf("Error creating output file - %s", err) + var outfile *os.File + + if conf.Outfile == "-" { + outfile = os.Stdout + } else { + outfile, err = os.Create(conf.Outfile) + if err != nil { + log.Fatalf("Error creating output file - %s", err) + } + defer outfile.Close() } - defer outfile.Close() var rangeQuery *elastic.RangeQuery