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

Commit 24657e3

Browse files
author
Hidetatsu Yaginuma
committed
temporarily unsupport krew
1 parent 6aeab40 commit 24657e3

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

command/runner.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func Run(args []string, version string) error {
5656
cmd.Stdin = os.Stdin
5757

5858
// when should not colorize, just run command and return
59-
if !shouldColorize {
59+
// TODO: right now, krew is unsupported by kubecolor but it should be.
60+
if !shouldColorize || subcommandInfo.IsKrew {
6061
cmd.Stdout = Stdout
6162
cmd.Stderr = Stderr
6263
if err := cmd.Start(); err != nil {

command/subcommand.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func ResolveSubcommand(args []string, config *KubecolorConfig) (bool, *kubectl.S
1616
// subcommandFound becomes false when subcommand is not found; e.g. "kubecolor --help"
1717
subcommandInfo, subcommandFound := kubectl.InspectSubcommandInfo(args)
1818

19+
if subcommandInfo.IsKrew {
20+
return false, subcommandInfo
21+
}
22+
1923
// if --plain found, it does not colorize
2024
if config.Plain {
2125
return false, subcommandInfo

kubectl/subcommand.go

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type SubcommandInfo struct {
1212
Help bool
1313
Recursive bool
1414
Short bool
15+
16+
IsKrew bool
1517
}
1618

1719
type FormatOption int
@@ -194,7 +196,21 @@ func CollectCommandlineOptions(args []string, info *SubcommandInfo) {
194196
}
195197

196198
func InspectSubcommandInfo(args []string) (*SubcommandInfo, bool) {
199+
// TODO: support krew
200+
contains := func(s []string, e string) bool {
201+
for _, a := range s {
202+
if a == e {
203+
return true
204+
}
205+
}
206+
return false
207+
}
197208
ret := &SubcommandInfo{}
209+
210+
if contains(args, "krew") {
211+
return &SubcommandInfo{IsKrew: true}, false
212+
}
213+
198214
CollectCommandlineOptions(args, ret)
199215

200216
for i := range args {

kubectl/subcommand_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func TestInspectSubcommandInfo(t *testing.T) {
6262

6363
{"apply", &SubcommandInfo{Subcommand: Apply}, true},
6464

65+
{"krew version", &SubcommandInfo{IsKrew: true}, false},
66+
6567
{"", &SubcommandInfo{}, false},
6668
}
6769
for _, tt := range tests {

0 commit comments

Comments
 (0)