Add support for passing manifests via stdin

This commit is contained in:
Yann Hamon 2020-10-31 14:02:15 +01:00
parent 42949e20b2
commit 7402d0fed8
7 changed files with 86 additions and 41 deletions

View file

@ -24,7 +24,7 @@ type jsono struct {
}
// JSON will output the results of the validation as a JSON
func JSON(w io.Writer, withSummary bool, verbose bool) Output {
func JSON(w io.Writer, withSummary bool, isStdin, verbose bool) Output {
return &jsono{
w: w,
withSummary: withSummary,

View file

@ -100,7 +100,7 @@ func TestJSONWrite(t *testing.T) {
},
} {
w := new(bytes.Buffer)
o := JSON(w, testCase.withSummary, testCase.verbose)
o := JSON(w, testCase.withSummary, false, testCase.verbose)
for _, res := range testCase.res {
o.Write(res.fileName, res.kind, res.name, res.version, res.err, res.skipped)

View file

@ -10,16 +10,18 @@ type text struct {
sync.Mutex
w io.Writer
withSummary bool
isStdin bool
verbose bool
files map[string]bool
nValid, nInvalid, nErrors, nSkipped int
}
// Text will output the results of the validation as a text
func Text(w io.Writer, withSummary, verbose bool) Output {
func Text(w io.Writer, withSummary, isStdin, verbose bool) Output {
return &text{
w: w,
withSummary: withSummary,
isStdin: isStdin,
verbose: verbose,
files: map[string]bool{},
nValid: 0,
@ -76,7 +78,11 @@ func (o *text) Flush() error {
if nFiles > 1 {
filesPlural = "s"
}
_, err = fmt.Fprintf(o.w, "Summary: %d resource%s found in %d file%s - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", nResources, resourcesPlural, nFiles, filesPlural, o.nValid, o.nInvalid, o.nErrors, o.nSkipped)
if o.isStdin {
_, err = fmt.Fprintf(o.w, "Summary: %d resource%s found parsing stdin - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", nResources, resourcesPlural, o.nValid, o.nInvalid, o.nErrors, o.nSkipped)
} else {
_, err = fmt.Fprintf(o.w, "Summary: %d resource%s found in %d file%s - Valid: %d, Invalid: %d, Errors: %d Skipped: %d\n", nResources, resourcesPlural, nFiles, filesPlural, o.nValid, o.nInvalid, o.nErrors, o.nSkipped)
}
}
return err

View file

@ -72,7 +72,7 @@ Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0
},
} {
w := new(bytes.Buffer)
o := Text(w, testCase.withSummary, testCase.verbose)
o := Text(w, testCase.withSummary, false, testCase.verbose)
for _, res := range testCase.res {
o.Write(res.fileName, res.kind, res.name, res.version, res.err, res.skipped)