Skip to content

Commit

Permalink
Fixing Error retrieving template from path when --format is not tem…
Browse files Browse the repository at this point in the history
…plate but template is provided (#556)
  • Loading branch information
Michal Slusarczyk committed Jul 13, 2020
1 parent 9a1d746 commit d9fa353
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/report/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ type Result struct {
}

func WriteResults(format string, output io.Writer, results Results, outputTemplate string, light bool) error {
if strings.HasPrefix(outputTemplate, "@") {
buf, err := ioutil.ReadFile(strings.TrimPrefix(outputTemplate, "@"))
if err != nil {
return xerrors.Errorf("Error retrieving template from path: %w", err)
}
outputTemplate = string(buf)
}

var writer Writer
switch format {
case "table":
writer = &TableWriter{Output: output, Light: light}
case "json":
writer = &JsonWriter{Output: output}
case "template":
if strings.HasPrefix(outputTemplate, "@") {
buf, err := ioutil.ReadFile(strings.TrimPrefix(outputTemplate, "@"))
if err != nil {
return xerrors.Errorf("Error retrieving template from path: %w", err)
}
outputTemplate = string(buf)
}
tmpl, err := template.New("output template").Funcs(template.FuncMap{
"escapeXML": func(input string) string {
escaped := &bytes.Buffer{}
Expand Down

0 comments on commit d9fa353

Please sign in to comment.