Support multi-resource files, include kind/version in logging

This commit is contained in:
Yann Hamon 2020-05-31 16:47:30 +02:00
parent a1c2e9dc68
commit 05da409a0a
5 changed files with 70 additions and 49 deletions

View file

@ -8,6 +8,8 @@ import (
type result struct {
Filename string `json:"filename"`
Kind string `json:"kind"`
Version string `json:"version"`
Status string `json:"status"`
Msg string `json:"msg"`
}
@ -32,7 +34,7 @@ func NewJSONOutput(withSummary bool, quiet bool) Output {
}
}
func (o *JSONOutput) Write(filename string, err error, skipped bool) {
func (o *JSONOutput) Write(filename, kind, version string, err error, skipped bool) {
o.Lock()
defer o.Unlock()
msg, st := "", ""
@ -56,7 +58,7 @@ func (o *JSONOutput) Write(filename string, err error, skipped bool) {
}
if !o.quiet || (s != VALID && s != SKIPPED) {
o.results = append(o.results, result{Filename: filename, Status: st, Msg: msg})
o.results = append(o.results, result{Filename: filename, Kind: kind, Version: version, Status: st, Msg: msg})
}
}

View file

@ -12,7 +12,7 @@ const (
)
type Output interface {
Write(filename string, err error, skipped bool)
Write(filename, kind, version string, err error, skipped bool)
Flush()
}

View file

@ -23,7 +23,7 @@ func NewTextOutput(withSummary, quiet bool) Output {
}
}
func (o *TextOutput) Write(filename string, err error, skipped bool) {
func (o *TextOutput) Write(filename, kind, version string, err error, skipped bool) {
o.Lock()
defer o.Unlock()
@ -31,18 +31,18 @@ func (o *TextOutput) Write(filename string, err error, skipped bool) {
switch {
case s == VALID:
if !o.quiet {
fmt.Printf("%s - file is valid\n", filename)
fmt.Printf("%s - %s is valid\n", filename, kind)
}
o.nValid++
case s == INVALID:
fmt.Printf("%s - invalid resource: %s\n", filename, err)
fmt.Printf("%s - %s is invalid: %s\n", filename, kind, err)
o.nInvalid++
case s == ERROR:
fmt.Printf("%s - failed validating resource: %s\n", filename, err)
fmt.Printf("%s - %s failed validation: %s\n", filename, kind, err)
o.nErrors++
case s == SKIPPED:
if !o.quiet {
fmt.Printf("%s - skipping resource\n", filename)
fmt.Printf("%s - %s skipped\n", filename, kind)
}
o.nSkipped++
}