From 7444a9f976c0140717f127012a947c53c0e1c330 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Fri, 9 Feb 2024 13:44:41 -0500 Subject: [PATCH] fix readme around templating options (#2612) Signed-off-by: Alex Goodman --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4897b6312..5b1c0fb54 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ Where the `formats` available are: ## Using templates -Syft lets you define custom output formats, using [Go templates](https://pkg.go.dev/text/template). Here's how it works: +Syft lets you define custom output formats, using [Go templates](https://pkg.go.dev/text/template) relative to the Syft JSON output. Here's how it works: - Define your format as a Go template, and save this template as a file. @@ -319,9 +319,9 @@ Syft lets you define custom output formats, using [Go templates](https://pkg.go. Here's what the `csv.tmpl` file might look like: ```gotemplate -"Package","Version Installed","Found by" -{{- range .Artifacts}} -"{{.Name}}","{{.Version}}","{{.FoundBy}}" +"Package","Version Installed", "Found by" +{{- range .artifacts}} +"{{.name}}","{{.version}}","{{.foundBy}}" {{- end}} ``` @@ -338,6 +338,9 @@ Syft also includes a vast array of utility templating functions from [sprig](htt Lastly, Syft has custom templating functions defined in `./syft/format/template/encoder.go` to help parse the passed-in JSON structs. +> [!NOTE] +> If you have templates being used before Syft v0.102.0 that are no longer working. This is because templating keys were relative to the internal go structs before this version whereas now the keys are relative to the Syft JSON output. To get the legacy behavior back you can set the `format.template.legacy` option to `true` in your configuration. + ## Multiple outputs Syft can also output _multiple_ files in differing formats by appending