Skip to content
This repository was archived by the owner on Jul 30, 2023. It is now read-only.

Commit ffe7415

Browse files
committed
exclude colorization if kubectl internal option is specified
1 parent 30c46a5 commit ffe7415

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

command/subcommand.go

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package command
22

33
import (
44
"os"
5+
"strings"
56

67
"github.com/hidetatz/kubecolor/kubectl"
78
"github.com/mattn/go-isatty"
@@ -21,6 +22,15 @@ func ResolveSubcommand(args []string, config *KubecolorConfig) (bool, *kubectl.S
2122
return false, subcommandInfo
2223
}
2324

25+
// if there is an argument starting with __,
26+
// the subcommand is probably an internal subcommand (like __completeNoDesc)
27+
// and should probably not be colorized
28+
for i := range args {
29+
if strings.HasPrefix(args[i], "__") {
30+
return false, subcommandInfo
31+
}
32+
}
33+
2434
// if subcommand is not found (e.g. kubecolor --help or just "kubecolor"),
2535
// it is treated as help because kubectl shows help for such input
2636
if !subcommandFound {

command/subcommand_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ func Test_ResolveSubcommand(t *testing.T) {
8181
expectedShouldColorize: true,
8282
expectedInfo: &kubectl.SubcommandInfo{Help: true},
8383
},
84+
{
85+
name: "when the internal argument is found, it won't colorize",
86+
args: []string{"__completeNoDesc", "get", "pods"},
87+
isOutputTerminal: func() bool { return true },
88+
conf: &KubecolorConfig{
89+
Plain: false,
90+
DarkBackground: true,
91+
ForceColor: false,
92+
KubectlCmd: "kubectl",
93+
},
94+
expectedShouldColorize: false,
95+
expectedInfo: &kubectl.SubcommandInfo{Subcommand: kubectl.Get},
96+
},
8497
{
8598
name: "when not tty, it won't colorize",
8699
args: []string{"get", "pods"},

0 commit comments

Comments
 (0)