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

Commit 1d787ce

Browse files
authored
Merge branch 'main' into jtyr-recursive
2 parents d1c867d + ffe7415 commit 1d787ce

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.goreleaser.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ builds:
1313
- -s -w
1414
- -X main.Version={{.Version}}
1515
goos:
16-
- windows
16+
# - windows
1717
- darwin
1818
- linux
1919
goarch:
@@ -37,9 +37,9 @@ archives:
3737
brews:
3838
- name: kubecolor
3939
tap:
40-
owner: dty1er
40+
owner: hidetatz
4141
name: homebrew-tap
42-
homepage: "https://github.com/dty1er/kubecolor"
42+
homepage: "https://github.com/hidetatz/kubecolor"
4343
description: "Colorize your kubectl output"
4444
folder: Formula
4545
install: |

command/subcommand.go

+12
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 {
@@ -54,6 +64,8 @@ func isColoringSupported(sc kubectl.Subcommand) bool {
5464
kubectl.Plugin,
5565
kubectl.Wait,
5666
kubectl.Run,
67+
kubectl.Ctx,
68+
kubectl.Ns,
5769
}
5870

5971
for _, u := range unsupported {

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"},

kubectl/subcommand.go

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const (
7070
Plugin
7171
Version
7272
Options
73+
Ctx
74+
Ns
7375
)
7476

7577
var strToSubcommand = map[string]Subcommand{
@@ -115,6 +117,8 @@ var strToSubcommand = map[string]Subcommand{
115117
"plugin": Plugin,
116118
"version": Version,
117119
"options": Options,
120+
"ctx": Ctx,
121+
"ns": Ns,
118122
}
119123

120124
func InspectSubcommand(command string) (Subcommand, bool) {

0 commit comments

Comments
 (0)