-verbose instead of -quiet, -quiet seems a better default

This commit is contained in:
Yann Hamon 2020-06-01 12:59:46 +02:00
parent 0ddf4e9a50
commit 1f019066c7
3 changed files with 18 additions and 27 deletions

29
main.go
View file

@ -118,16 +118,7 @@ func validateFile(r io.Reader, regs []registry.Registry, k8sVersion string, c *c
type arrayParam []string type arrayParam []string
func (ap *arrayParam) String() string { func (ap *arrayParam) String() string {
s := "" return strings.Join(*ap, " - ")
for _, param := range *ap {
if s == "" {
s += param
} else {
s += " - " + param
}
}
return s
} }
func (ap *arrayParam) Set(value string) error { func (ap *arrayParam) Set(value string) error {
@ -135,12 +126,12 @@ func (ap *arrayParam) Set(value string) error {
return nil return nil
} }
func getLogger(outputFormat string, printSummary, quiet bool) (output.Output, error) { func getLogger(outputFormat string, printSummary, verbose bool) (output.Output, error) {
switch { switch {
case outputFormat == "text": case outputFormat == "text":
return output.Text(printSummary, quiet), nil return output.Text(printSummary, verbose), nil
case outputFormat == "json": case outputFormat == "json":
return output.JSON(printSummary, quiet), nil return output.JSON(printSummary, verbose), nil
default: default:
return nil, fmt.Errorf("-output must be text or json") return nil, fmt.Errorf("-output must be text or json")
} }
@ -158,7 +149,7 @@ func skipKindsMap(skipKindsCSV string) map[string]bool {
func realMain() int { func realMain() int {
var files, dirs, schemas arrayParam var files, dirs, schemas arrayParam
var skipKindsCSV, k8sVersion, outputFormat string var skipKindsCSV, k8sVersion, outputFormat string
var printSummary, strict, quiet bool var summary, strict, verbose bool
var nWorkers int var nWorkers int
var err error var err error
@ -166,16 +157,16 @@ func realMain() int {
flag.Var(&files, "file", "file to validate (can be specified multiple times)") flag.Var(&files, "file", "file to validate (can be specified multiple times)")
flag.Var(&dirs, "dir", "directory to validate (can be specified multiple times)") flag.Var(&dirs, "dir", "directory to validate (can be specified multiple times)")
flag.Var(&schemas, "schema", "file containing an additional Schema (can be specified multiple times)") flag.Var(&schemas, "schema", "file containing an additional Schema (can be specified multiple times)")
flag.BoolVar(&printSummary, "printsummary", false, "print a summary at the end") flag.BoolVar(&summary, "summary", false, "print a summary at the end")
flag.IntVar(&nWorkers, "workers", 4, "number of routines to run in parallel") flag.IntVar(&nWorkers, "n", 4, "number of routines to run in parallel")
flag.StringVar(&skipKindsCSV, "skipKinds", "", "comma-separated list of kinds to ignore") flag.StringVar(&skipKindsCSV, "skip", "", "comma-separated list of kinds to ignore")
flag.BoolVar(&strict, "strict", false, "disallow additional properties not in schema") flag.BoolVar(&strict, "strict", false, "disallow additional properties not in schema")
flag.StringVar(&outputFormat, "output", "text", "output format - text, json") flag.StringVar(&outputFormat, "output", "text", "output format - text, json")
flag.BoolVar(&quiet, "quiet", false, "quiet output - only print invalid files, and errors") flag.BoolVar(&verbose, "verbose", false, "print results for all resources")
flag.Parse() flag.Parse()
var o output.Output var o output.Output
if o, err = getLogger(outputFormat, printSummary, quiet); err != nil { if o, err = getLogger(outputFormat, summary, verbose); err != nil {
fmt.Println(err) fmt.Println(err)
return 1 return 1
} }

View file

@ -15,7 +15,7 @@ type result struct {
type jsono struct { type jsono struct {
withSummary bool withSummary bool
quiet bool verbose bool
results []result results []result
nValid, nInvalid, nErrors, nSkipped int nValid, nInvalid, nErrors, nSkipped int
} }
@ -23,7 +23,7 @@ type jsono struct {
func JSON(withSummary bool, quiet bool) Output { func JSON(withSummary bool, quiet bool) Output {
return &jsono{ return &jsono{
withSummary: withSummary, withSummary: withSummary,
quiet: quiet, verbose: quiet,
results: []result{}, results: []result{},
nValid: 0, nValid: 0,
nInvalid: 0, nInvalid: 0,
@ -54,7 +54,7 @@ func (o *jsono) Write(filename, kind, version string, err error, skipped bool) {
o.nSkipped++ o.nSkipped++
} }
if !o.quiet || (s != VALID && s != SKIPPED) { if o.verbose || s == VALID || s == SKIPPED {
o.results = append(o.results, result{Filename: filename, Kind: kind, Version: version, Status: st, Msg: msg}) o.results = append(o.results, result{Filename: filename, Kind: kind, Version: version, Status: st, Msg: msg})
} }
} }

View file

@ -8,14 +8,14 @@ import (
type text struct { type text struct {
sync.Mutex sync.Mutex
withSummary bool withSummary bool
quiet bool verbose bool
nValid, nInvalid, nErrors, nSkipped int nValid, nInvalid, nErrors, nSkipped int
} }
func Text(withSummary, quiet bool) Output { func Text(withSummary, verbose bool) Output {
return &text{ return &text{
withSummary: withSummary, withSummary: withSummary,
quiet: quiet, verbose: verbose,
nValid: 0, nValid: 0,
nInvalid: 0, nInvalid: 0,
nErrors: 0, nErrors: 0,
@ -29,7 +29,7 @@ func (o *text) Write(filename, kind, version string, err error, skipped bool) {
switch status(err, skipped) { switch status(err, skipped) {
case VALID: case VALID:
if !o.quiet { if !o.verbose {
fmt.Printf("%s - %s is valid\n", filename, kind) fmt.Printf("%s - %s is valid\n", filename, kind)
} }
o.nValid++ o.nValid++
@ -40,7 +40,7 @@ func (o *text) Write(filename, kind, version string, err error, skipped bool) {
fmt.Printf("%s - %s failed validation: %s\n", filename, kind, err) fmt.Printf("%s - %s failed validation: %s\n", filename, kind, err)
o.nErrors++ o.nErrors++
case SKIPPED: case SKIPPED:
if !o.quiet { if o.verbose {
fmt.Printf("%s - %s skipped\n", filename, kind) fmt.Printf("%s - %s skipped\n", filename, kind)
} }
o.nSkipped++ o.nSkipped++