Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wagoodman
Copy link
Contributor

This PR adds a new --file option that writes the report bytes out to the given file path consistent with anchore/syft#530 .

Closes #207

Signed-off-by: Alex Goodman <[email protected]>
@wagoodman wagoodman requested a review from a team October 5, 2021 19:00
@wagoodman wagoodman self-assigned this Oct 5, 2021
Signed-off-by: Alex Goodman <[email protected]>
@wagoodman wagoodman enabled auto-merge (squash) October 5, 2021 19:11
Copy link
Contributor

@luhring luhring left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines +13 to +28
path := strings.TrimSpace(appConfig.File)
switch len(path) {
case 0:
return os.Stdout, nop, nil
default:
reportFile, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return nil, nop, fmt.Errorf("unable to create report file: %w", err)
}
return reportFile, func() error {
if !appConfig.Quiet {
fmt.Printf("Report written to %q\n", path)
}
return reportFile.Close()
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

very small nit: This is a good example of code that's well structured, but could be more readable if vertical spacing were leveraged more. Blank lines to separate subsections of thoughts can be really nice for readers looking to get a sense of structure, particular with regard to control flow — e.g., using blank lines to make return lines more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add some space to break this up 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wagoodman wagoodman merged commit cd3b414 into main Oct 5, 2021
@wagoodman wagoodman deleted the output-to-file branch October 5, 2021 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add an option to output the report into a file rather than redirecting the output

2 participants