Skip to content

Commit d9fa353

Browse files
author
Michal Slusarczyk
authored
Fixing Error retrieving template from path when --format is not template but template is provided (#556)
1 parent 9a1d746 commit d9fa353

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pkg/report/writer.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@ type Result struct {
2828
}
2929

3030
func WriteResults(format string, output io.Writer, results Results, outputTemplate string, light bool) error {
31-
if strings.HasPrefix(outputTemplate, "@") {
32-
buf, err := ioutil.ReadFile(strings.TrimPrefix(outputTemplate, "@"))
33-
if err != nil {
34-
return xerrors.Errorf("Error retrieving template from path: %w", err)
35-
}
36-
outputTemplate = string(buf)
37-
}
38-
3931
var writer Writer
4032
switch format {
4133
case "table":
4234
writer = &TableWriter{Output: output, Light: light}
4335
case "json":
4436
writer = &JsonWriter{Output: output}
4537
case "template":
38+
if strings.HasPrefix(outputTemplate, "@") {
39+
buf, err := ioutil.ReadFile(strings.TrimPrefix(outputTemplate, "@"))
40+
if err != nil {
41+
return xerrors.Errorf("Error retrieving template from path: %w", err)
42+
}
43+
outputTemplate = string(buf)
44+
}
4645
tmpl, err := template.New("output template").Funcs(template.FuncMap{
4746
"escapeXML": func(input string) string {
4847
escaped := &bytes.Buffer{}

0 commit comments

Comments
 (0)