ahmetb / kubectx

Faster way to switch between clusters and namespaces in kubectl
https://kubectx.dev
Apache License 2.0
17.71k stars 1.26k forks source link

why help exits with 1? #69

Closed tivvit closed 6 years ago

tivvit commented 6 years ago

https://github.com/ahmetb/kubectx/blob/master/kubectx#L40

ahmetb commented 6 years ago

There’s often no consensus on whether —help should exit with error in gnu tools and similar tools like curl, git etc. This is fine since the flag is meant to be used interactively and therefore prints to stderr, which is another indicator of it is not meant the help output should be used by the programs. 😊

If you try many tools, you’ll see some exit successfully on help and some won’t.

My question would be more like what difference does this make for you in terms of kubectx context? Do you need to exit this with success status?

tivvit commented 6 years ago

git --help and curl -h both returned 0 status on my system. To be fair I thought it is very common to return 0 staus for help. At least I thought exit status 1 is for erroneous states.

But I get your point some tools may exit with status 1 for help.

I am developing a tool for installing and keeping useful scripts up to date. It is based on https://github.com/slackhq/magic-cli but purely in bash and the installation is based on Make. Part of the installation is generating help which failed on exit status 1. It was simple to solve (kubectx -h || true) but I was just surprised. I do not consider myself a bash guru so I asked ;) The tool I am writing will be hopefully open-sourced soon.

I think there is no solution to this issue, therefore you can close it.

BTW thanks for the great tools :+1:

ahmetb commented 6 years ago

I think this can be fixed easily and I'm ok with fixing it for --help.

It can also be used in brew formula as a test, which does a nastier test today: https://github.com/Homebrew/homebrew-core/blob/a21926ac32853a1e64fdf23c74cec2d9e98cb0a8/Formula/kubectx.rb#L26-L29

Updating the exit code for --help would likely break this installation script, as it expects to see (1) exit code 1 (2) "USAGE:" in --help stderr output. So we just need to tag a release and update brew formula with this.

Are you interested in fixing this in kubectx? We probably need to just move exit out of usage function.

tivvit commented 6 years ago

Yes I will gladly prepare PR. Does the same apply to kubens?

On Mon, Aug 13, 2018, 18:58 Ahmet Alp Balkan notifications@github.com wrote:

I think this can be fixed easily and I'm ok with fixing it for --help.

It can also be used in brew formula as a test, which does a nastier test today: https://github.com/Homebrew/homebrew-core/blob/a21926ac32853a1e64fdf23c74cec2d9e98cb0a8/Formula/kubectx.rb#L26-L29

Updating the exit code for --help would likely break this installation script, as it expects to see (1) exit code 1 (2) "USAGE:" in --help stderr output. So we just need to tag a release and update brew formula with this.

Are you interested in fixing this in kubectx? We probably need to just move exit out of usage function.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ahmetb/kubectx/issues/69#issuecomment-412588867, or mute the thread https://github.com/notifications/unsubscribe-auth/ADPFo5dO0PW4HHJvEfLLxUBcHvHgpXbGks5uQbApgaJpZM4V5H6I .

ahmetb commented 6 years ago

Yes.

tivvit commented 6 years ago

prepared PR to homebrew too https://github.com/Homebrew/homebrew-core/pull/31288

ahmetb commented 6 years ago

We still haven't tagged a release yet, I'll ping you when we're ready to tag another release.

tivvit commented 6 years ago

thanks :)