mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 00:16:38 +01:00
* feat: add preRun func to version to restore stdout Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com> * test: add test to capture version in output Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com> * change stdout buffering to log to be opt-in per command Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
38 lines
587 B
Go
38 lines
587 B
Go
package ui
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/internal/log"
|
|
)
|
|
|
|
func newLogWriter() io.Writer {
|
|
l := logWriter{}
|
|
l.r = bufio.NewReader(&l.buf)
|
|
return &l
|
|
}
|
|
|
|
type logWriter struct {
|
|
buf bytes.Buffer
|
|
r *bufio.Reader
|
|
}
|
|
|
|
func (l *logWriter) Write(data []byte) (n int, err error) {
|
|
l.buf.Write(data)
|
|
s, err := l.r.ReadString('\n')
|
|
s = strings.TrimRight(s, "\n")
|
|
for s != "" {
|
|
log.Trace("[unexpected stdout] " + s)
|
|
n += len(s)
|
|
if err != nil {
|
|
break
|
|
}
|
|
s, err = l.r.ReadString('\n')
|
|
s = strings.TrimRight(s, "\n")
|
|
}
|
|
return n, err
|
|
}
|