mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* add output to file option Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * log errors on close of the report destination Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove file option from persistent args Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update file option comments and logging Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * allow for multiple UI fallback options Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update UI select signatures + tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
30 lines
599 B
Go
30 lines
599 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/internal/log"
|
|
)
|
|
|
|
func reportWriter() (io.Writer, func() error, error) {
|
|
nop := func() error { return nil }
|
|
|
|
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 {
|
|
log.Infof("report written to file=%q", path)
|
|
return reportFile.Close()
|
|
}, nil
|
|
}
|
|
}
|