mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-19 01:47:02 +00:00
output: extract iniitializer function
This commit is contained in:
parent
bf29e486d2
commit
daab22bc8a
2 changed files with 14 additions and 14 deletions
|
|
@ -136,19 +136,6 @@ func (ap *arrayParam) Set(value string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getLogger(outputFormat string, printSummary, verbose bool) (output.Output, error) {
|
||||
w := os.Stdout
|
||||
|
||||
switch {
|
||||
case outputFormat == "text":
|
||||
return output.Text(w, printSummary, verbose), nil
|
||||
case outputFormat == "json":
|
||||
return output.JSON(w, printSummary, verbose), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("-output must be text or json")
|
||||
}
|
||||
}
|
||||
|
||||
func skipKindsMap(skipKindsCSV string) map[string]bool {
|
||||
splitKinds := strings.Split(skipKindsCSV, ",")
|
||||
skipKinds := map[string]bool{}
|
||||
|
|
@ -281,7 +268,7 @@ func realMain() int {
|
|||
}()
|
||||
|
||||
var o output.Output
|
||||
if o, err = getLogger(outputFormat, summary, verbose); err != nil {
|
||||
if o, err = output.New(outputFormat, summary, verbose); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,19 @@ type Output interface {
|
|||
Flush() error
|
||||
}
|
||||
|
||||
func New(outputFormat string, printSummary, verbose bool) (Output, error) {
|
||||
w := os.Stdout
|
||||
|
||||
switch {
|
||||
case outputFormat == "text":
|
||||
return Text(w, printSummary, verbose), nil
|
||||
case outputFormat == "json":
|
||||
return JSON(w, printSummary, verbose), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("`outputFormat` must be 'text' or 'json'")
|
||||
}
|
||||
}
|
||||
|
||||
func status(kind, name string, err error, skipped bool) int {
|
||||
if name == "" && kind == "" && err == nil && skipped == false {
|
||||
return EMPTY
|
||||
|
|
|
|||
Loading…
Reference in a new issue