From ebdbf09d95d1266228807c35fb770a441d923deb Mon Sep 17 00:00:00 2001 From: Mark Bestavros Date: Tue, 10 Oct 2023 19:19:01 -0400 Subject: [PATCH] feat: Implement option for custom output destinations Signed-off-by: Mark Bestavros --- output/output.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/output/output.go b/output/output.go index bcd120d5f0..3ce689c012 100644 --- a/output/output.go +++ b/output/output.go @@ -21,6 +21,7 @@ type Options struct { SuppressExceptions bool ShowSkipped bool JUnitHideMessage bool + File *os.File } // The defined output formats represent all of the supported formats @@ -37,23 +38,27 @@ const ( // Get returns a type that can render output in the given format. func Get(format string, options Options) Outputter { + if options.File == nil { + options.File = os.Stdout + } + switch format { case OutputStandard: - return &Standard{Writer: os.Stdout, NoColor: options.NoColor, SuppressExceptions: options.SuppressExceptions, Tracing: options.Tracing, ShowSkipped: options.ShowSkipped} + return &Standard{Writer: options.File, NoColor: options.NoColor, SuppressExceptions: options.SuppressExceptions, Tracing: options.Tracing, ShowSkipped: options.ShowSkipped} case OutputJSON: - return NewJSON(os.Stdout) + return NewJSON(options.File) case OutputTAP: - return NewTAP(os.Stdout) + return NewTAP(options.File) case OutputTable: - return NewTable(os.Stdout) + return NewTable(options.File) case OutputJUnit: - return NewJUnit(os.Stdout, options.JUnitHideMessage) + return NewJUnit(options.File, options.JUnitHideMessage) case OutputGitHub: - return NewGitHub(os.Stdout) + return NewGitHub(options.File) case OutputAzureDevOps: - return NewAzureDevOps(os.Stdout) + return NewAzureDevOps(options.File) default: - return NewStandard(os.Stdout) + return NewStandard(options.File) } }