Skip to content
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

go usage and help messages write to stderr instead of stdout #17284

Closed
fschr opened this issue Sep 29, 2016 · 3 comments
Closed

go usage and help messages write to stderr instead of stdout #17284

fschr opened this issue Sep 29, 2016 · 3 comments

Comments

@fschr
Copy link

fschr commented Sep 29, 2016


Version

go 1.7 darwin/amd64

OS + Architecture

GOARCH="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did I do?

go --help and go [subcommand] --help

What did you expect to see?

I expected these commands to write to stdout. I was trying to see what the -i flag in go build -i does, so I ran the command go build --help | grep -- -i.

What did you see instead?

My buffer was flooded with the entire go build --help message because it writes to stderr instead of stdout. This means I have to run go {subcommand} --help 2>&1 | grep -- -{flag} when figuring out what a flag does.

However, when running commands like go env and go version, output is written to stdout. This leads to confusion: when should I have to combine stderr and stdout? What if there was a genuine error in the go {subcommand} that I run? I don't want to pipe that through grep and miss it, it may be important.

I think go should pick a file descriptor---either stdout or stderr---to write all go output to. In my opinion, go should only ever write to stderr if the binary itself fails in some respect. That way I don't miss any errors because I'm piping all of stderr through grep, head, and the like.

@0xmohit
Copy link
Contributor

0xmohit commented Sep 29, 2016

You could use the "go help [topic]" instead. Saying go help build would write to stdout. Refer to go help for the list of commands and help topics.

Ideally, help messages should be sent to stdout.

@fschr
Copy link
Author

fschr commented Sep 29, 2016

Ideally, help messages should be sent to stdout.

Exactly. So is this behavior intended? I don't think it is.

@slrz
Copy link

slrz commented Sep 29, 2016

It is intended. Conceptually, what you're seeing in response to "go build --help" is an error message. This is also signaled by the program exiting with a status of 2. Go build does not accept a "--help" flag and thus exits, printing usage information for your convenience.

If you want to access its help, use "go help" as the message is telling you. This is not a bug.

@fschr fschr closed this as completed Sep 29, 2016
@golang golang locked and limited conversation to collaborators Sep 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants