-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaks out output logger so we can extend in the future
- Loading branch information
Brendan Ryan
committed
Jul 28, 2019
1 parent
82138a4
commit dabc0c4
Showing
5 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kubeval | ||
|
||
import ( | ||
"github.com/instrumenta/kubeval/log" | ||
) | ||
|
||
// TODO (brendanryan) move these structs to `/log` once we have removed the potential | ||
// circular dependancy between this package and `/log` | ||
|
||
// OutputManager controls how results of the `ccheck` evaluation will be recorded | ||
// and reported to the end user. | ||
type OutputManager interface { | ||
Put(r ValidationResult) error | ||
Flush() error | ||
} | ||
|
||
// STDOutputManager reports `ccheck` results to stdout. | ||
type STDOutputManager struct { | ||
} | ||
|
||
// NewDefaultStdOutputManager instantiates a new instance of STDOutputManager using | ||
// the default logger. | ||
func NewSTDOutputManager() *STDOutputManager { | ||
return &STDOutputManager{} | ||
} | ||
|
||
func (s *STDOutputManager) Put(result ValidationResult) error { | ||
|
||
if len(result.Errors) > 0 { | ||
log.Warn("The file", result.FileName, "contains an invalid", result.Kind) | ||
for _, desc := range result.Errors { | ||
log.Info("--->", desc) | ||
} | ||
} else if result.Kind == "" { | ||
log.Success("The file", result.FileName, "contains an empty YAML document") | ||
} else if !result.ValidatedAgainstSchema { | ||
log.Warn("The file", result.FileName, "containing a", result.Kind, "was not validated against a schema") | ||
} else { | ||
log.Success("The file", result.FileName, "contains a valid", result.Kind) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *STDOutputManager) Flush() error { | ||
// no op | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ func Error(message ...interface{}) { | |
red := color.New(color.FgRed) | ||
red.Println(message...) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters