Fix color output on Windows (#220)

This commit is contained in:
Jason Harmon
2020-05-15 18:26:00 -04:00
committed by GitHub
parent 01bd237baa
commit 401188fefd
2 changed files with 10 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/ahmetb/kubectx/internal/cmdutil"
"github.com/ahmetb/kubectx/internal/env"
"github.com/ahmetb/kubectx/internal/printer"
"github.com/fatih/color"
)
type Op interface {
@@ -15,15 +16,15 @@ type Op interface {
}
func main() {
cmdutil.PrintDeprecatedEnvWarnings(os.Stderr, os.Environ())
cmdutil.PrintDeprecatedEnvWarnings(color.Error, os.Environ())
op := parseArgs(os.Args[1:])
if err := op.Run(os.Stdout, os.Stderr); err != nil {
printer.Error(os.Stderr, err.Error())
if err := op.Run(color.Output, color.Error); err != nil {
printer.Error(color.Error, err.Error())
if _, ok := os.LookupEnv(env.EnvDebug); ok {
// print stack trace in verbose mode
fmt.Fprintf(os.Stderr, "[DEBUG] error: %+v\n", err)
fmt.Fprintf(color.Error, "[DEBUG] error: %+v\n", err)
}
defer os.Exit(1)
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/ahmetb/kubectx/internal/cmdutil"
"github.com/ahmetb/kubectx/internal/env"
"github.com/ahmetb/kubectx/internal/printer"
"github.com/fatih/color"
)
type Op interface {
@@ -15,14 +16,14 @@ type Op interface {
}
func main() {
cmdutil.PrintDeprecatedEnvWarnings(os.Stderr, os.Environ())
cmdutil.PrintDeprecatedEnvWarnings(color.Error, os.Environ())
op := parseArgs(os.Args[1:])
if err := op.Run(os.Stdout, os.Stderr); err != nil {
printer.Error(os.Stderr, err.Error())
if err := op.Run(color.Output, color.Error); err != nil {
printer.Error(color.Error, err.Error())
if _, ok := os.LookupEnv(env.EnvDebug); ok {
// print stack trace in verbose mode
fmt.Fprintf(os.Stderr, "[DEBUG] error: %+v\n", err)
fmt.Fprintf(color.Error, "[DEBUG] error: %+v\n", err)
}
defer os.Exit(1)
}