1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 18:06:55 +00:00
kyverno/cmd/cli/kubectl-kyverno/commands/json/scan/output.go

49 lines
859 B
Go
Raw Normal View History

package scan
import (
"encoding/json"
"fmt"
"io"
jsonengine "github.com/kyverno/kyverno-json/pkg/json-engine"
)
type output interface {
println(args ...any)
responses(responses ...jsonengine.Response)
}
type textOutput struct {
out io.Writer
}
func (t *textOutput) println(args ...any) {
fmt.Fprintln(t.out, args...)
}
func (t *textOutput) responses(responses ...jsonengine.Response) {
}
type jsonOutput struct {
out io.Writer
}
func (t *jsonOutput) println(args ...any) {
}
func (t *jsonOutput) responses(responses ...jsonengine.Response) {
payload, err := json.MarshalIndent(responses, "", " ")
if err != nil {
fmt.Fprintln(t.out, err)
} else {
fmt.Fprintln(t.out, string(payload))
}
}
func newOutput(out io.Writer, format string) output {
if format == "json" {
return &jsonOutput{out: out}
}
return &textOutput{out: out}
}