feat: use STDOUT when report file not specified (#1642)

* feat: use STDOUT when report file not specified

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: update tests

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: use only '-' for stdout report

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

---------

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>
This commit is contained in:
Bryce Thuilot authored and GitHub committed 2024-12-05 09:44:07 -06:00
1 parent ed205a5f63
commit f3adda07ca
3 files changed
+33 -22

No files matched your search

+10 -1
View File
@@ -283,8 +283,17 @@ func findingSummaryAndExit(findings []report.Finding, cmd *cobra.Command, cfg co
// write report if desired
reportPath, _ := cmd.Flags().GetString("report-path")
ext, _ := cmd.Flags().GetString("report-format")
if reportPath != "" {
if err := report.Write(findings, cfg, ext, reportPath); err != nil {
reportWriter := os.Stdout
if reportPath != "-" {
reportWriter, err = os.Create(reportPath)
if err != nil {
log.Fatal().Err(err).Msg("could not create report file")
}
}
if err = report.Write(findings, cfg, ext, reportWriter); err != nil {
log.Fatal().Err(err).Msg("could not write")
}
}