Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple CSV format template to the templates/ directory and tweak docs #1366

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Grype lets you define custom output formats, using [Go templates](https://golang

**Please note:** Templates can access information about the system they are running on, such as environment variables. You should never run untrusted templates.

Here's what the `csv.tmpl` file might look like:
There are several example templates in the [templates/](https://github.com/anchore/grype/tree/main/templates) directory. Here's what the `(csv.tmpl)[https://github.com/anchore/grype/blob/main/templates/csv.tmpl]` file looks like:

```gotemplate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we take the example out of the readme and just point users to the templates directory to see examples? If nothing else, it at least eliminates one location to update if the data model ever changes enough that these need to be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea, I will update the patch.

"Package","Version Installed","Vulnerability ID","Severity"
Expand All @@ -280,7 +280,7 @@ Here's what the `csv.tmpl` file might look like:
{{- end}}
```

Which would produce output like:
Which would produce output formatted with comma-separated values:

```text
"Package","Version Installed","Vulnerability ID","Severity"
Expand Down
4 changes: 4 additions & 0 deletions templates/csv.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"Package","Version Installed","Vulnerability ID","Severity"
{{- range .Matches}}
"{{.Artifact.Name}}","{{.Artifact.Version}}","{{.Vulnerability.ID}}","{{.Vulnerability.Severity}}"
{{- end}}