@@ -19,14 +19,15 @@ package util
19
19
import (
20
20
"errors"
21
21
"fmt"
22
+ "io"
22
23
23
24
"github.com/GoogleContainerTools/container-diff/pkg/util"
24
25
"github.com/sirupsen/logrus"
25
26
)
26
27
27
28
type Result interface {
28
29
OutputStruct () interface {}
29
- OutputText (resultType string , format string ) error
30
+ OutputText (writer io. Writer , resultType string , format string ) error
30
31
}
31
32
32
33
type AnalyzeResult struct {
@@ -41,14 +42,14 @@ func (r ListAnalyzeResult) OutputStruct() interface{} {
41
42
return r
42
43
}
43
44
44
- func (r ListAnalyzeResult ) OutputText (resultType string , format string ) error {
45
+ func (r ListAnalyzeResult ) OutputText (writer io. Writer , resultType string , format string ) error {
45
46
analysis , valid := r .Analysis .([]string )
46
47
if ! valid {
47
48
logrus .Error ("Unexpected structure of Analysis. Should be of type []string" )
48
49
return fmt .Errorf ("Could not output %s analysis result" , r .AnalyzeType )
49
50
}
50
51
r .Analysis = analysis
51
- return TemplateOutputFromFormat (r , "ListAnalyze" , format )
52
+ return TemplateOutputFromFormat (writer , r , "ListAnalyze" , format )
52
53
53
54
}
54
55
@@ -73,7 +74,7 @@ func (r MultiVersionPackageAnalyzeResult) OutputStruct() interface{} {
73
74
return output
74
75
}
75
76
76
- func (r MultiVersionPackageAnalyzeResult ) OutputText (resultType string , format string ) error {
77
+ func (r MultiVersionPackageAnalyzeResult ) OutputText (writer io. Writer , resultType string , format string ) error {
77
78
analysis , valid := r .Analysis .(map [string ]map [string ]PackageInfo )
78
79
if ! valid {
79
80
logrus .Error ("Unexpected structure of Analysis. Should be of type map[string]map[string]PackageInfo" )
@@ -91,7 +92,7 @@ func (r MultiVersionPackageAnalyzeResult) OutputText(resultType string, format s
91
92
AnalyzeType : r .AnalyzeType ,
92
93
Analysis : strAnalysis ,
93
94
}
94
- return TemplateOutputFromFormat (strResult , "MultiVersionPackageAnalyze" , format )
95
+ return TemplateOutputFromFormat (writer , strResult , "MultiVersionPackageAnalyze" , format )
95
96
}
96
97
97
98
type SingleVersionPackageAnalyzeResult AnalyzeResult
@@ -115,7 +116,7 @@ func (r SingleVersionPackageAnalyzeResult) OutputStruct() interface{} {
115
116
return output
116
117
}
117
118
118
- func (r SingleVersionPackageAnalyzeResult ) OutputText (diffType string , format string ) error {
119
+ func (r SingleVersionPackageAnalyzeResult ) OutputText (writer io. Writer , diffType string , format string ) error {
119
120
analysis , valid := r .Analysis .(map [string ]PackageInfo )
120
121
if ! valid {
121
122
logrus .Error ("Unexpected structure of Analysis. Should be of type map[string]PackageInfo" )
@@ -133,7 +134,7 @@ func (r SingleVersionPackageAnalyzeResult) OutputText(diffType string, format st
133
134
AnalyzeType : r .AnalyzeType ,
134
135
Analysis : strAnalysis ,
135
136
}
136
- return TemplateOutputFromFormat (strResult , "SingleVersionPackageAnalyze" , format )
137
+ return TemplateOutputFromFormat (writer , strResult , "SingleVersionPackageAnalyze" , format )
137
138
}
138
139
139
140
type SingleVersionPackageLayerAnalyzeResult AnalyzeResult
@@ -173,7 +174,7 @@ func (r SingleVersionPackageLayerAnalyzeResult) OutputStruct() interface{} {
173
174
return output
174
175
}
175
176
176
- func (r SingleVersionPackageLayerAnalyzeResult ) OutputText (diffType string , format string ) error {
177
+ func (r SingleVersionPackageLayerAnalyzeResult ) OutputText (writer io. Writer , diffType string , format string ) error {
177
178
analysis , valid := r .Analysis .(PackageLayerDiff )
178
179
if ! valid {
179
180
logrus .Error ("Unexpected structure of Analysis. Should be of type PackageLayerDiff" )
@@ -205,7 +206,7 @@ func (r SingleVersionPackageLayerAnalyzeResult) OutputText(diffType string, form
205
206
AnalyzeType : r .AnalyzeType ,
206
207
Analysis : analysisOutput ,
207
208
}
208
- return TemplateOutputFromFormat (strResult , "SingleVersionPackageLayerAnalyze" , format )
209
+ return TemplateOutputFromFormat (writer , strResult , "SingleVersionPackageLayerAnalyze" , format )
209
210
}
210
211
211
212
type PackageOutput struct {
@@ -263,7 +264,7 @@ func (r FileAnalyzeResult) OutputStruct() interface{} {
263
264
return r
264
265
}
265
266
266
- func (r FileAnalyzeResult ) OutputText (analyzeType string , format string ) error {
267
+ func (r FileAnalyzeResult ) OutputText (writer io. Writer , analyzeType string , format string ) error {
267
268
analysis , valid := r .Analysis .([]util.DirectoryEntry )
268
269
if ! valid {
269
270
logrus .Error ("Unexpected structure of Analysis. Should be of type []DirectoryEntry" )
@@ -286,7 +287,7 @@ func (r FileAnalyzeResult) OutputText(analyzeType string, format string) error {
286
287
AnalyzeType : r .AnalyzeType ,
287
288
Analysis : strAnalysis ,
288
289
}
289
- return TemplateOutputFromFormat (strResult , "FileAnalyze" , format )
290
+ return TemplateOutputFromFormat (writer , strResult , "FileAnalyze" , format )
290
291
}
291
292
292
293
type FileLayerAnalyzeResult AnalyzeResult
@@ -310,7 +311,7 @@ func (r FileLayerAnalyzeResult) OutputStruct() interface{} {
310
311
return r
311
312
}
312
313
313
- func (r FileLayerAnalyzeResult ) OutputText (analyzeType string , format string ) error {
314
+ func (r FileLayerAnalyzeResult ) OutputText (writer io. Writer , analyzeType string , format string ) error {
314
315
analysis , valid := r .Analysis .([][]util.DirectoryEntry )
315
316
if ! valid {
316
317
logrus .Error ("Unexpected structure of Analysis. Should be of type []DirectoryEntry" )
@@ -338,7 +339,7 @@ func (r FileLayerAnalyzeResult) OutputText(analyzeType string, format string) er
338
339
AnalyzeType : r .AnalyzeType ,
339
340
Analysis : strDirectoryEntries ,
340
341
}
341
- return TemplateOutputFromFormat (strResult , "FileLayerAnalyze" , format )
342
+ return TemplateOutputFromFormat (writer , strResult , "FileLayerAnalyze" , format )
342
343
}
343
344
344
345
type SizeAnalyzeResult AnalyzeResult
@@ -353,7 +354,7 @@ func (r SizeAnalyzeResult) OutputStruct() interface{} {
353
354
return r
354
355
}
355
356
356
- func (r SizeAnalyzeResult ) OutputText (analyzeType string , format string ) error {
357
+ func (r SizeAnalyzeResult ) OutputText (writer io. Writer , analyzeType string , format string ) error {
357
358
analysis , valid := r .Analysis .([]SizeEntry )
358
359
if ! valid {
359
360
logrus .Error ("Unexpected structure of Analysis. Should be of type []SizeEntry" )
@@ -371,7 +372,7 @@ func (r SizeAnalyzeResult) OutputText(analyzeType string, format string) error {
371
372
AnalyzeType : r .AnalyzeType ,
372
373
Analysis : strAnalysis ,
373
374
}
374
- return TemplateOutputFromFormat (strResult , "SizeAnalyze" , format )
375
+ return TemplateOutputFromFormat (writer , strResult , "SizeAnalyze" , format )
375
376
}
376
377
377
378
type SizeLayerAnalyzeResult AnalyzeResult
@@ -386,7 +387,7 @@ func (r SizeLayerAnalyzeResult) OutputStruct() interface{} {
386
387
return r
387
388
}
388
389
389
- func (r SizeLayerAnalyzeResult ) OutputText (analyzeType string , format string ) error {
390
+ func (r SizeLayerAnalyzeResult ) OutputText (writer io. Writer , analyzeType string , format string ) error {
390
391
analysis , valid := r .Analysis .([]SizeEntry )
391
392
if ! valid {
392
393
logrus .Error ("Unexpected structure of Analysis. Should be of type []SizeEntry" )
@@ -404,5 +405,5 @@ func (r SizeLayerAnalyzeResult) OutputText(analyzeType string, format string) er
404
405
AnalyzeType : r .AnalyzeType ,
405
406
Analysis : strAnalysis ,
406
407
}
407
- return TemplateOutputFromFormat (strResult , "SizeLayerAnalyze" , format )
408
+ return TemplateOutputFromFormat (writer , strResult , "SizeLayerAnalyze" , format )
408
409
}
0 commit comments