Skip to content

Commit

Permalink
This adds the ability to force colored output
Browse files Browse the repository at this point in the history
Feature suggested in #87
  • Loading branch information
ian-howell committed Jul 16, 2019
1 parent 312975f commit 478f10e
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 @@ -9,6 +9,7 @@ import (
"path/filepath"
"runtime"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand All @@ -22,6 +23,10 @@ var (
date = "unknown"
)

// 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 @@ -43,6 +48,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 @@ -119,6 +128,7 @@ func init() {
RootCmd.Flags().BoolVarP(&kubeval.OpenShift, "openshift", "", false, "Use OpenShift schemas instead of upstream Kubernetes")
RootCmd.Flags().BoolVarP(&kubeval.Strict, "strict", "", false, "Disallow additional properties not in schema")
RootCmd.Flags().BoolVarP(&kubeval.IgnoreMissingSchemas, "ignore-missing-schemas", "", false, "Skip validation for resource definitions without a schema")
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 478f10e

Please sign in to comment.