File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "os"
5+
46 "github.com/mgutz/ansi"
57 "github.com/spf13/cobra"
8+ "golang.org/x/crypto/ssh/terminal"
69)
710
811const rootCmdLongUsage = `
@@ -40,6 +43,8 @@ func New() *cobra.Command {
4043 PersistentPreRun : func (cmd * cobra.Command , args []string ) {
4144 if nc , _ := cmd .Flags ().GetBool ("no-color" ); nc {
4245 ansi .DisableColors (true )
46+ } else if ! cmd .Flags ().Changed ("no-color" ) {
47+ ansi .DisableColors (! terminal .IsTerminal (int (os .Stdout .Fd ())))
4348 }
4449 },
4550 RunE : func (cmd * cobra.Command , args []string ) error {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ require (
2020 github.com/spf13/cobra v1.0.0
2121 github.com/spf13/pflag v1.0.5
2222 github.com/stretchr/testify v1.5.1
23+ golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
2324 google.golang.org/grpc v1.30.0
2425 gopkg.in/yaml.v2 v2.3.0
2526 k8s.io/api v0.18.6
You can’t perform that action at this time.
0 commit comments