mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
feat(report): considering App.Writer when printing results (#1722)
Co-authored-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -60,7 +60,7 @@ func (c *Option) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Option) initPreScanOptions() error {
|
func (c *Option) initPreScanOptions() error {
|
||||||
if err := c.ReportOption.Init(c.Logger); err != nil {
|
if err := c.ReportOption.Init(c.Context.App.Writer, c.Logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.DBOption.Init(); err != nil {
|
if err := c.DBOption.Init(); err != nil {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (c *Option) Init() (err error) {
|
|||||||
c.CustomHeaders.Set(c.tokenHeader, c.token)
|
c.CustomHeaders.Set(c.tokenHeader, c.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.ReportOption.Init(c.Logger); err != nil {
|
if err = c.ReportOption.Init(c.Context.App.Writer, c.Logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ type ReportOption struct {
|
|||||||
// these variables are populated by Init()
|
// these variables are populated by Init()
|
||||||
VulnType []string
|
VulnType []string
|
||||||
SecurityChecks []string
|
SecurityChecks []string
|
||||||
Output *os.File
|
Output io.Writer
|
||||||
Severities []dbTypes.Severity
|
Severities []dbTypes.Severity
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ func NewReportOption(c *cli.Context) ReportOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the ReportOption
|
// Init initializes the ReportOption
|
||||||
func (c *ReportOption) Init(logger *zap.SugaredLogger) error {
|
func (c *ReportOption) Init(output io.Writer, logger *zap.SugaredLogger) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.Template != "" {
|
if c.Template != "" {
|
||||||
@@ -83,13 +84,15 @@ func (c *ReportOption) Init(logger *zap.SugaredLogger) error {
|
|||||||
c.vulnType = ""
|
c.vulnType = ""
|
||||||
c.securityChecks = ""
|
c.securityChecks = ""
|
||||||
|
|
||||||
c.Output = os.Stdout
|
// The output is os.Stdout by default
|
||||||
if c.output != "" {
|
if c.output != "" {
|
||||||
if c.Output, err = os.Create(c.output); err != nil {
|
if output, err = os.Create(c.output); err != nil {
|
||||||
return xerrors.Errorf("failed to create an output file: %w", err)
|
return xerrors.Errorf("failed to create an output file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Output = output
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func TestReportReportConfig_Init(t *testing.T) {
|
|||||||
Output: tt.fields.Output,
|
Output: tt.fields.Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.Init(logger.Sugar())
|
err := c.Init(os.Stdout, logger.Sugar())
|
||||||
|
|
||||||
// tests log messages
|
// tests log messages
|
||||||
var gotMessages []string
|
var gotMessages []string
|
||||||
|
|||||||
Reference in New Issue
Block a user