8000 Fixed kubecolor coloring `oc rsh` by applejag · Pull Request #117 · kubecolor/kubecolor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed kubecolor coloring oc rsh #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2024
Merged

Fixed kubecolor coloring oc rsh #117

merged 2 commits into from
May 1, 2024

Conversation

applejag
Copy link
Member
@applejag applejag commented May 1, 2024

Description

Disables coloring on the rsh subcommand, which comes from oc rsh.

Could change so unknown commands don't get colored at all, which could prevent this in other commands. But for now I just went with adding rsh as a known subcommand.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

What you changed

  • Changed Subcommand to a string
  • Added 'rsh' as unsupported command

Why you think we should change it

Fixes issue for oc users, especially since we declare oc support in the README now.

Related issue (if exists)

Closes #108

@applejag applejag added the bug Something isn't working label May 1, 2024
@applejag applejag self-assigned this May 1, 2024
@applejag applejag requested a review from prune998 May 1, 2024 14:21
Comment on lines +71 to 78
// oc (OpenShift CLI) specific subcommands
kubectl.Rsh: {},
}

return true
func isColoringSupported(sc kubectl.Subcommand) bool {
_, found := unsupported[sc]
return !found
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this from a slice to a map does have performance implications.

When benchmarking, a slice was as expected faster when looking up the first element in the list, but the map approach was actually faster when looking up the last element.

$ go test -bench=. ./command -benchtime=5s
goos: linux
goarch: amd64
pkg: github.com/kubecolor/kubecolor/command
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkIsColoringSupported_rsh-8         	489333993	        16.41 ns/op
BenchmarkIsColoringSupportedMap_rsh-8      	531382500	        13.78 ns/op
BenchmarkIsColoringSupported_attach-8      	1000000000	         4.193 ns/op
BenchmarkIsColoringSupportedMap_attach-8   	680426997	         9.031 ns/op
PASS
ok  	github.com/kubecolor/kubecolor/command	29.554s

However the code is way smaller and in my opinion the benefit of the clean code wins over the cost of some nanoseconds (btw a nanosecond is 0.000000001 seconds)

@prune998 prune998 merged commit 7d31f14 into main May 1, 2024
@prune998 prune998 deleted the bugfix/oc-rsh branch May 1, 2024 14:31
@applejag applejag mentioned this pull request May 23, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

oc rsh breaks when using kubecolor
2 participants
0