fix readme around templating options (#2612)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman 2024-02-09 13:44:41 -05:00 committed by GitHub
parent 8683cba081
commit 7444a9f976
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -305,7 +305,7 @@ Where the `formats` available are:
## Using templates ## 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. - 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: Here's what the `csv.tmpl` file might look like:
```gotemplate ```gotemplate
"Package","Version Installed","Found by" "Package","Version Installed", "Found by"
{{- range .Artifacts}} {{- range .artifacts}}
"{{.Name}}","{{.Version}}","{{.FoundBy}}" "{{.name}}","{{.version}}","{{.foundBy}}"
{{- end}} {{- 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. 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 ## Multiple outputs
Syft can also output _multiple_ files in differing formats by appending Syft can also output _multiple_ files in differing formats by appending