diff --git a/cli/reporter/cli_reporter.go b/cli/reporter/cli_reporter.go index 3d0bbc47..347eec9d 100644 --- a/cli/reporter/cli_reporter.go +++ b/cli/reporter/cli_reporter.go @@ -101,6 +101,13 @@ func NewReporter(format Format, incognito bool) *Reporter { } } +// This allows the packer-plugin-cnspec to set the output writer directly +// The plugin needs this to work the the packer output +func (r *Reporter) WithOutput(out io.Writer) *Reporter { + r.out = out + return r +} + func (r *Reporter) WriteReport(ctx context.Context, data *policy.ReportCollection) error { switch r.Format { case Compact: diff --git a/cli/reporter/file_handler.go b/cli/reporter/file_handler.go index 60d2e5c9..8cf20724 100644 --- a/cli/reporter/file_handler.go +++ b/cli/reporter/file_handler.go @@ -27,9 +27,6 @@ func (h *localFileHandler) WriteReport(ctx context.Context, report *policy.Repor } defer f.Close() //nolint: errcheck reporter := NewReporter(h.format, false) - if err != nil { - return err - } reporter.out = f err = reporter.WriteReport(ctx, report) if err != nil {