Skip to content

Commit

Permalink
Fix color output on Windows (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdharmon authored May 15, 2020
1 parent 01bd237 commit 401188f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cmd/kubectx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ 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 {
Run(stdout, stderr io.Writer) error
}

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)
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/kubens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ 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 {
Run(stdout, stderr io.Writer) error
}

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)
}
Expand Down

0 comments on commit 401188f

Please sign in to comment.