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

Commit de347c9

Browse files
authored
Merge branch 'main' into patch-1
2 parents 51d01ad + a815efa commit de347c9

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
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

+13
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 {
@@ -44,6 +54,7 @@ func isColoringSupported(sc kubectl.Subcommand) bool {
4454
// when you add something here, it won't be colorized
4555
unsupported := []kubectl.Subcommand{
4656
kubectl.Create,
57+
kubectl.Debug,
4758
kubectl.Delete,
4859
kubectl.Edit,
4960
kubectl.Attach,
@@ -54,6 +65,8 @@ func isColoringSupported(sc kubectl.Subcommand) bool {
5465
kubectl.Plugin,
5566
kubectl.Wait,
5667
kubectl.Run,
68+
kubectl.Ctx,
69+
kubectl.Ns,
5770
}
5871

5972
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const (
7070
Plugin
7171
Version
7272
Options
73+
Ctx
74+
Ns
75+
Debug
7376
)
7477

7578
var strToSubcommand = map[string]Subcommand{
@@ -115,6 +118,9 @@ var strToSubcommand = map[string]Subcommand{
115118
"plugin": Plugin,
116119
"version": Version,
117120
"options": Options,
121+
"ctx": Ctx,
122+
"ns": Ns,
123+
"debug": Debug,
118124
}
119125

120126
func InspectSubcommand(command string) (Subcommand, bool) {
@@ -187,7 +193,7 @@ func CollectCommandlineOptions(args []string, info *SubcommandInfo) {
187193
info.NoHeader = true
188194
} else if args[i] == "-w" || args[i] == "--watch" {
189195
info.Watch = true
190-
} else if args[i] == "--recursive=true" {
196+
} else if args[i] == "--recursive=true" || args[i] == "--recursive" {
191197
info.Recursive = true
192198
} else if args[i] == "-h" || args[i] == "--help" {
193199
info.Help = true

kubectl/subcommand_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ func TestInspectSubcommandInfo(t *testing.T) {
5151

5252
{"explain pod", &SubcommandInfo{Subcommand: Explain}, true},
5353
{"explain pod --recursive=true", &SubcommandInfo{Subcommand: Explain, Recursive: true}, true},
54-
// "--recursive true" is not acceptable by kubectl explain
55-
{"explain pod --recursive true", &SubcommandInfo{Subcommand: Explain}, true},
54+
{"explain pod --recursive", &SubcommandInfo{Subcommand: Explain, Recursive: true}, true},
5655

5756
{"version", &SubcommandInfo{Subcommand: Version}, true},
5857
{"version --client", &SubcommandInfo{Subcommand: Version}, true},

0 commit comments

Comments
 (0)