google / subcommands

Go subcommand library.
Apache License 2.0
749 stars 48 forks source link

println is redirected to stderr #33

Closed xylo04 closed 3 years ago

xylo04 commented 4 years ago

When using println in the subcommand, the output is directed to stderr instead of stdout. This is important for command line utilities which differentiate between status messages and output which should be piped elsewhere, e.g. a file or another process.

xylo04 commented 4 years ago

Worth noting, using fmt.Println() is a workaround, but doesn't help if the subcommand is calling another library that uses println.

slewiskelly commented 4 years ago

I would consider using fmt.Println(...) to be the correct use, as opposed to a workaround.

This package does not use the println function directly, and this package cannot, and should not, control where output of a subcommand is being directed.

The println function always directs to stderr, and am not sure that it is intended for use in production code.

Also note that the language spec, suggests that implementations may change or even be removed entirely.