From 24657e3885ef5e5ac3eebbd2dae57db1c1fbdc89 Mon Sep 17 00:00:00 2001 From: Hidetatsu Yaginuma Date: Wed, 5 May 2021 11:44:55 +0900 Subject: [PATCH 1/2] temporarily unsupport krew --- command/runner.go | 3 ++- command/subcommand.go | 4 ++++ kubectl/subcommand.go | 16 ++++++++++++++++ kubectl/subcommand_test.go | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/command/runner.go b/command/runner.go index 50c8e86..03a922e 100644 --- a/command/runner.go +++ b/command/runner.go @@ -56,7 +56,8 @@ func Run(args []string, version string) error { cmd.Stdin = os.Stdin // when should not colorize, just run command and return - if !shouldColorize { + // TODO: right now, krew is unsupported by kubecolor but it should be. + if !shouldColorize || subcommandInfo.IsKrew { cmd.Stdout = Stdout cmd.Stderr = Stderr if err := cmd.Start(); err != nil { diff --git a/command/subcommand.go b/command/subcommand.go index 7be6329..7b0c453 100644 --- a/command/subcommand.go +++ b/command/subcommand.go @@ -16,6 +16,10 @@ func ResolveSubcommand(args []string, config *KubecolorConfig) (bool, *kubectl.S // subcommandFound becomes false when subcommand is not found; e.g. "kubecolor --help" subcommandInfo, subcommandFound := kubectl.InspectSubcommandInfo(args) + if subcommandInfo.IsKrew { + return false, subcommandInfo + } + // if --plain found, it does not colorize if config.Plain { return false, subcommandInfo diff --git a/kubectl/subcommand.go b/kubectl/subcommand.go index 361db9d..ac4b678 100644 --- a/kubectl/subcommand.go +++ b/kubectl/subcommand.go @@ -12,6 +12,8 @@ type SubcommandInfo struct { Help bool Recursive bool Short bool + + IsKrew bool } type FormatOption int @@ -194,7 +196,21 @@ func CollectCommandlineOptions(args []string, info *SubcommandInfo) { } func InspectSubcommandInfo(args []string) (*SubcommandInfo, bool) { + // TODO: support krew + contains := func(s []string, e string) bool { + for _, a := range s { + if a == e { + return true + } + } + return false + } ret := &SubcommandInfo{} + + if contains(args, "krew") { + return &SubcommandInfo{IsKrew: true}, false + } + CollectCommandlineOptions(args, ret) for i := range args { diff --git a/kubectl/subcommand_test.go b/kubectl/subcommand_test.go index 33153fe..a116e09 100644 --- a/kubectl/subcommand_test.go +++ b/kubectl/subcommand_test.go @@ -62,6 +62,8 @@ func TestInspectSubcommandInfo(t *testing.T) { {"apply", &SubcommandInfo{Subcommand: Apply}, true}, + {"krew version", &SubcommandInfo{IsKrew: true}, false}, + {"", &SubcommandInfo{}, false}, } for _, tt := range tests { From 1b12b5d729028a0b267ac45d2ed91255f03e1873 Mon Sep 17 00:00:00 2001 From: Hidetatsu Yaginuma Date: Wed, 5 May 2021 11:46:07 +0900 Subject: [PATCH 2/2] explicitly mention Krew is unsupported --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index eb306eb..e09a6d7 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,10 @@ When you don't set `KUBECTL_COMMAND`, then `kubectl` is used by default. Because kubecolor internally calls `kubectl` command, if you are using unsupported kubectl version, it's also not supported by kubecolor. Kubernetes version support policy can be found in [official doc](https://kubernetes.io/docs/setup/release/version-skew-policy/). +## Krew + +[Krew](https://krew.sigs.k8s.io/) is unsupported for now. + ## Contributions Always welcome. Just opening an issue should be also greatful.