Skip to content

Commit

Permalink
Merge branch 'feat/force-color' of https://github.com/ian-howell/kubeval
Browse files Browse the repository at this point in the history
 into ian-howell-feat/force-color
  • Loading branch information
garethr committed Jul 20, 2019
2 parents 333017a + 478f10e commit 6c4cfc0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

multierror "github.com/hashicorp/go-multierror"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand All @@ -25,6 +26,10 @@ var (
directories = []string{}
)

// forceColor tells kubeval to use colored output even if
// stdout is not a TTY
var forceColor bool

// RootCmd represents the the command to run when kubeval is run
var RootCmd = &cobra.Command{
Use: "kubeval <file> [file...]",
Expand All @@ -46,6 +51,10 @@ var RootCmd = &cobra.Command{
windowsStdinIssue = true
}
}
// Assert that colors will definitely be used if requested
if forceColor {
color.NoColor = false
}
// We detect whether we have anything on stdin to process if we have no arguments
// or if the argument is a -
if (len(args) < 1 || args[0] == "-") && !windowsStdinIssue && ((stat.Mode() & os.ModeCharDevice) == 0) {
Expand Down Expand Up @@ -164,6 +173,7 @@ func init() {
RootCmd.Flags().BoolVarP(&kubeval.IgnoreMissingSchemas, "ignore-missing-schemas", "", false, "Skip validation for resource definitions without a schema")
RootCmd.Flags().StringSliceVarP(&directories, "directories", "d", []string{}, "A comma-separated list of directories to recursively search for YAML documents")
RootCmd.Flags().BoolVarP(&kubeval.ExitOnError, "exit-on-error", "", false, "Immediately stop execution when the first error is encountered")
RootCmd.Flags().BoolVarP(&forceColor, "force-color", "", false, "Force colored output even if stdout is not a TTY")
RootCmd.SetVersionTemplate(`{{.Version}}`)
viper.BindPFlag("schema_location", RootCmd.Flags().Lookup("schema-location"))
RootCmd.PersistentFlags().StringP("filename", "f", "stdin", "filename to be displayed when testing manifests read from stdin")
Expand Down

0 comments on commit 6c4cfc0

Please sign in to comment.